This code uses an identity column to create a rank.declare @t table (Seq int not null identity(1,1) primary key clustered,val int not null )declare @rank table ( Rank int primary key clustered,val int not null )-- Load values in order by val column to be rankedinsert into @t (val)select top 100 percent valfrom(select top 200 -- Generate random test data values val=(abs(checksum(newid()))%14)+347from master.dbo.sysobjects aorder by a.id) border by val-- Load into rank tableinsert into @rank ( Rank,val )select top 100 percent Rank = min(Seq), valfrom @tgroup by valorder by min(Seq)select * from @rankResults:(200 row(s) affected)(14 row(s) affected)Rank val ----------- ----------- 1 34712 34826 34939 35050 35165 35281 353103 354120 355136 356153 357161 358175 359190 360(14 row(s) affected)
CODO ERGO SUM