Quantcast
Channel: Answers for "How to generate a unique record using server variables ?"
Viewing all articles
Browse latest Browse all 6

Answer by Usman Butt

$
0
0
I guess using DENSE_RANK() function is one way of doing it. For e.g. DECLARE @Data table (col1 varchar(5),col2 varchar(5),col3 varchar(5),col4 varchar(5),Primary Key(col1,col2 )) insert into @Data select 'A','1','11','33' union all select 'A','2','21','r3' union all select 'B','1','2a','3g' union all select 'C','1','2','f3' SELECT DENSE_RANK() OVER (ORDER BY [col1]) col0,* FROM @Data AS D which gives the desired output.

Viewing all articles
Browse latest Browse all 6

Trending Articles