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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Increment second column on key change

Author  Topic 

jimib
Starting Member

3 Posts

Posted - 2014-07-21 : 14:11:25
I have a table like this:

1 a
2 a
3 b
4 b
5 b
6 c

and I need this:

1 a 1
2 a 2
3 b 1
4 b 2
5 b 3
6 c 1

can anyone help?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-07-21 : 14:17:56
Use the ROW_NUMBER() function for this.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -