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 |
KlausEngel
Yak Posting Veteran
85 Posts |
Posted - 2010-12-03 : 12:12:22
|
I have what I believe is a simple question:I need to write a query that returns a result set and adds a row number to each result set. How do I keep incrementing the row number?DECLARE @row_numSET @row_num = @row_num+1SELECT @row_num, column1, column3FROM MyTableDesired result set:1, col1Val1, col3Val12, col1Val2, col3Val23, col1Val3, co3lVal3etc |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-12-03 : 12:23:49
|
SELECT row_num = row_number() over (order by column1, column3), column1, column3FROM MyTable==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|