You're on SS2000, right?Here's one way: (this won't be very efficient so if you have large table post again.)declare @t table (Pol_Num varchar(10), SeqNo int, InsInd char(1), InsOnBene int)insert @tselect 'F1111111', 1, 'Y', NULL union allselect 'F1111111', 2, 'N', NULL union allselect 'F1111111', 3, 'Y', NULL union allselect 'G2222222', 1, 'N', NULL union allselect 'G2222222', 2, 'Y', NULL union allselect 'G2222222', 3, 'Y', NULLupdate a set a.InsOnBene = d.InsOnBenefrom @t ajoin ( select a.Pol_num ,a.seqNo ,( select count(*) from @t where pol_num = a.pol_num and SeqNo <= a.seqNo and InsInd = 'Y' ) as InsOnBene from @t a ) d on d.Pol_num = a.Pol_num and d.seqNo = a.SeqNo select * from @tOUTPUT:Pol_Num SeqNo InsInd InsOnBene---------- ----------- ------ -----------F1111111 1 Y 1F1111111 2 N 1F1111111 3 Y 2G2222222 1 N 0G2222222 2 Y 1G2222222 3 Y 2
Be One with the OptimizerTG