/*create table #cat_jesus (account char(3), somedate smalldatetime)insert #cat_jesusselect 'aaa','1/1/2001'union all select 'aaa','1/1/2001'union all select 'aaa','2/1/2002'union all select 'aaa','2/1/2002'union all select 'bbb','1/1/2001'union all select 'bbb','1/1/2001'*/--step one, add the seq colalter table #cat_jesus add seq tinyintgodeclare @seq tinyint, @lastaccount char(3), @lastdate smalldatetimeupdate #cat_jesusset @seq = seq = case when @lastaccount = account and @lastdate = somedate then @seq + 1 else 1 end, @lastaccount = account, @lastdate = somedategoselect * from #cat_jesusgo
BUT . . . there is one problem. The data in cat_jesus must be ordered by account,somedate. Because the above example is a temp table, it will retain the order of the insert, but that is not guarrenteed. You may have to play around with working this in another working table where you can force the order and then somehow updating your original table. It's gonna depend on your ddl. My guess is you won't get this to work...<O>