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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Row number

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_table
Result:
state descritpion
US United States of AMerica
IT Italy
JP Japan
Now I need to add automatically a column with row number:
rowNumber state descritpion
1 US United States of AMerica
2 IT Italy
3 JP Japan
Is 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 #temp
from my_table
select * from #temp
drop table #temp

2.
select rank=count(*), t1.state, t1.description
from my_table t1, my_table t2
where t1.state + t1.description >= t2.state + t2.description
group by t1.state, t1.description
order by 1

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -