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 |
|
PaTRiCKDRD
Yak Posting Veteran
55 Posts |
Posted - 2007-07-04 : 08:10:52
|
| Hi everyone!I have a variable that takes an initial value,e.g. 5Does anyone know of a way I can add and increment this value to a query result?i.e. attach a column that takes values 5, 6, 7 and so on to the query result,sth like this:SELECT @new_aa + 1, col2, col3 FROM ...which doesn't work (returns a column having a value of 1 in all rows)!Thanks in advance! |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-04 : 08:44:36
|
| Try the new ROW_NUMBER() function available in SQL Server 2005.Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-04 : 08:45:44
|
| SELECT ROW_NUMBER() OVER (ORDER BY Col1) + @New_AA AS <SomeColNameHere>, col2, col3 FROM Table1Peter LarssonHelsingborg, Sweden |
 |
|
|
PaTRiCKDRD
Yak Posting Veteran
55 Posts |
Posted - 2007-07-04 : 09:09:07
|
| thank you very much peso!I feel relieved and grateful! |
 |
|
|
|
|
|