Not sure how you are ranking within each group but here is an example of updating the table and ranking on the fly:set nocount oncreate table #junk (dt datetime, nm varchar(10), rank int null)goinsert #junk (dt, nm)select '1/1/06', 'Jeff' union select '1/1/06', 'Chris' union select '1/1/06', 'John' union select '3/1/06', 'Michelle' union select '3/1/06', 'Peter' union select '3/1/06', 'Mary'goselect * from #junkprint 'Update the table with rank value by group'update a set rank = (select count(*) from #junk where datediff(day,dt,a.dt) = 0 and nm <= a.nm)from #junk aselect * from #junkprint 'Select out the values calculating rank on the fly'select dt ,nm ,rank = (select count(*) from #junk where datediff(day,dt,a.dt) = 0 and nm <= a.nm)from #junk agodrop table #junkoutput:Update the table with rank value by groupdt nm rank ------------------------------------------------------ ---------- ----------- 2006-01-01 00:00:00.000 Chris 12006-01-01 00:00:00.000 Jeff 22006-01-01 00:00:00.000 John 32006-03-01 00:00:00.000 Mary 12006-03-01 00:00:00.000 Michelle 22006-03-01 00:00:00.000 Peter 3Select out the values calculating rank on the flydt nm rank ------------------------------------------------------ ---------- ----------- 2006-01-01 00:00:00.000 Chris 12006-01-01 00:00:00.000 Jeff 22006-01-01 00:00:00.000 John 32006-03-01 00:00:00.000 Mary 12006-03-01 00:00:00.000 Michelle 22006-03-01 00:00:00.000 Peter 3
Be One with the OptimizerTG