Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Generate RowNumber with SubGroup Basis

Author  Topic 

aoriju
Posting Yak Master

156 Posts

Posted - 2009-07-30 : 09:28:06
DECLARE @tbl_test AS TABLE(ID INT,PNAME VARCHAR(20))
INSERT INTO @tbl_Test(ID,PNAME) VALUES(1,'RIJU')
INSERT INTO @tbl_Test(ID,PNAME) VALUES(2,'SENIL')
INSERT INTO @tbl_Test(ID,PNAME) VALUES(1,'ANOOP')
INSERT INTO @tbl_Test(ID,PNAME) VALUES(1,'SAJIN')
INSERT INTO @tbl_Test(ID,PNAME) VALUES(3,'ANTONY')
INSERT INTO @tbl_Test(ID,PNAME) VALUES(3,'ABDU')


I want to Get Sl No as

1,2,3 for RIJU,ANOOP,SAJIN
1 FOR SENIL
1,2 FOR ANTONY,ABDU

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-30 : 09:37:04
Method 2
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-30 : 09:37:37
[code]
select *, SNo = row_number() over (partition by ID order by PNAME)
from @tbl_test
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -