1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- Example of how to use row_number to generate sequential number starting from 0 by group
create table #test(names varchar(100) )
2
insert into #test
select 'Suresh'union all
select 'Ramesh' union all
select 'Kant' union all
select 'Jerald' union all
select 'Clara' union all
select 'Ramesh' union all
select 'Kant' union all
select 'Jerald' union all
select 'John'
select * from #test
select row_number() over (partition by names order by names) as sno, names from #test
drop table #test
Generate sequential number using row_number function
This post is licensed under CC BY 4.0 by the author.