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 |
|
azamsharp
Posting Yak Master
201 Posts |
Posted - 2010-01-04 : 10:36:14
|
| How can I get a running column of incrementing integers along with my result?Mohammad Azam www.azamsharp.net |
|
|
azamsharp
Posting Yak Master
201 Posts |
Posted - 2010-01-04 : 10:42:38
|
| got it I just used the row_number with over.Mohammad Azam www.azamsharp.net |
 |
|
|
DP978
Constraint Violating Yak Guru
269 Posts |
Posted - 2010-01-04 : 10:42:53
|
| [code]DECLARE @myTable TABLE (myID int Identity, col1 CHAR(2), col2 CHAR(2))Insert @myTableSelect 'A','A' Union allSelect 'A','B' Union allSelect 'B','A'Select * from @myTable[/code]Play around with "myID int Identity" to get desired results as well, the format is IDENTITY(Seed,Increment). So... DECLARE @myTable TABLE (myID int Identity(2,3), col1 CHAR(2), col2 CHAR(2))Starts at 2 and goes up by 3 each row. |
 |
|
|
azamsharp
Posting Yak Master
201 Posts |
Posted - 2010-01-04 : 11:16:59
|
| @DP978, In the above technique you will HAVE to insert into the @MyTable in order to generate the ID. The Row_Number with the over technique allows to generate this without requiring any TABLE.Mohammad Azam www.azamsharp.net |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-01-05 : 01:41:36
|
quote: Originally posted by azamsharp @DP978, In the above technique you will HAVE to insert into the @MyTable in order to generate the ID. The Row_Number with the over technique allows to generate this without requiring any TABLE.Mohammad Azam www.azamsharp.net
Yes go for Row_number() functionAlso see how it can be effectively used for other purposes as wellhttp://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspxMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|