here is the table structure with some sample data:
create table proceduremaster
( procedureid int primary key ,
procedurecode varchar(10),
ParentProcedureID int)
Insert into proceduremaster(procedureid, procedurecode)
select 86, '0062'
union all
select 87,'0062A'
union all
select 88,'0062B'
union all
select 93,8680
union
select 94,8680
Desired o/p - for first 3 rows parentProcedureId would be 86 and for last 2 rows parentprocedureId would be 93
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/