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 |
|
chadbryant5
Starting Member
32 Posts |
Posted - 2005-04-15 : 10:41:41
|
| This is probably a stupid question, but how do I get a sequence # column in my T-SQL query? If I run a query in Query Analyzer, I get a grid that has the resultset. Down the left side, each row is numbered 1...n. I'd just like this numbering to exist as a column.IE:Value Frequency Sequence---------------------------------10203 3334 110399 3300 2...12993 4 13000Is this possible?Thanks in advanceChad |
|
|
PW
Yak Posting Veteran
95 Posts |
Posted - 2005-04-15 : 10:44:28
|
| You'd need to create a temp table or table variable with an Identity column, select your resultset into that table with an ORDER BY, then select the final result out of the temp table/variable.In SQL2005, you'll be able to do this with the new Row_Number ranking function. |
 |
|
|
chadbryant5
Starting Member
32 Posts |
Posted - 2005-04-15 : 10:51:37
|
| Ok, that makes sense. I'm suprised t-sql at this point doesn't have a way to do this though. Anyway, thanks for the tip!!Chad |
 |
|
|
|
|
|