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
 Sequential Number Generate

Author  Topic 

pgmr1998
Yak Posting Veteran

66 Posts

Posted - 2010-07-29 : 15:16:46
Anyone know how I can generate a sequential number and have it as my first col during my Select Clause? I would like to begin with the number 1 and have it increment by 1 for each output line. Thanks...

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-07-29 : 15:24:58
Look into the ROW_NUMBER() function.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-29 : 16:50:09
select
row_number() over (order by (select 1)) as rownum,
*
from your_table


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-03 : 04:29:54
More about row_number() function
http://beyondrelational.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
   

- Advertisement -