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 |
|
scozzese
Starting Member
12 Posts |
Posted - 2004-12-17 : 09:46:47
|
| I've have the following query:Select state, description from my_tableResult:state descritpionUS United States of AMericaIT ItalyJP JapanNow I need to add automatically a column with row number:rowNumber state descritpion1 US United States of AMerica2 IT Italy3 JP JapanIs there a command to add to my query to get the rownumber?Thankyou in advanced. |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-12-17 : 10:04:32
|
no, there isn't. there are 2 ways:1. create table #temp (rownum int identity(1,1), state varchar(50), description varchar(50))Select state, description into #tempfrom my_tableselect * from #tempdrop table #temp2.select rank=count(*), t1.state, t1.description from my_table t1, my_table t2where t1.state + t1.description >= t2.state + t2.description group by t1.state, t1.description order by 1Go with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|