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 2005 Forums
 Transact-SQL (2005)
 select query

Author  Topic 

ehsanshekari
Starting Member

1 Post

Posted - 2008-11-13 : 11:41:58
hi

I have a table with a column named firstname. I want to write a select query that returns two columns, one is firstname and the other is the row number. for example

id name
1 jack
2 john

how can I do that?
I think I have to declare a variable and add it by 1 each time in my select query but I don't know how. everything I wrote was wrong.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-13 : 11:44:22
[code]select row_number() over (order by firstname) as id,firstname as name from yourtable [/code]
Go to Top of Page
   

- Advertisement -