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
 Auto Increment --Numbering rows

Author  Topic 

sqlspider
Starting Member

16 Posts

Posted - 2005-09-01 : 13:04:37
How can I issue a SQL statement to assign incrementing numbers starting from a particular row. For e.g.,

col1 col2
----- -----
aaa 123
... 345
xxx 001
yyy 002
zzz 003

I would like to have numbering in col2 to start where col1=XXX to ZZZ.

Thank you

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-02 : 01:35:21
Try this

Select col1, (Select count(*) from yourTable where col1<=T.col1) as col2 from yorTable T

Madhivanan

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

- Advertisement -