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.
| Author |
Topic |
|
amsqlguy
Yak Posting Veteran
89 Posts |
Posted - 2010-09-08 : 10:04:09
|
| Guys,I have following table in which I am trying to figure out a way to update the seq column as per the logic below by grouping empid and role.EMPID ROLE SEQ1 1 11 1 21 2 12 1 12 2 12 2 22 2 32 2 4Any suggestions or inputs would help.Thanks |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2010-09-08 : 11:10:16
|
| row_number over() to the rescue!http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
kunal.mehta
Yak Posting Veteran
83 Posts |
Posted - 2010-09-09 : 09:28:11
|
| declare @Customer table(CustomerID int,RoleID int,seq int)insert into @Customer values (1,1,0)insert into @Customer values (1,1,0)insert into @Customer values (1,2,0)insert into @Customer values (2,1,0)insert into @Customer values (2,2,0)insert into @Customer values (2,2,0)insert into @Customer values (2,2,0)insert into @Customer values (2,2,0)select customerid,RoleID,row_number() over(partition by customerid,roleid order by customerid,roleid asc) from @Customer |
 |
|
|
|
|
|
|
|