Desired Result-- For all 3 rows inserted ParentProcedureID would be 86,86,86 as '0062' is parent of all procedureCode...

i wrote the query as-UPDATE PSET P.ParentProcedureID = (SELECT TOP 1 PP.ProcedureID FROM ProcedureMaster PP WHERE rtrim(PP.ProcedureCode)= LEFT(RTRIM(P.ProcedureCode),LEN(RTRIM(P.ProcedureCode))-1) )FROM ProcedureMaster PWHERE right(rtrim(P.ProcedureCode),1) ='A'but its not working correctly.please suggest