Autoincrement field in MS SQL 2005 select

Hi,

 I have a query:  select Name from T1;

  I am trying to achieve this:

Name Order
Apple 1
Banana 2
Allison 3

in other words an autoincremented number in the second column...how can I do this?
LuckyLucksAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
select Name, rn = row_number() over ( order by Name) from T1;
0
 
bharathmosurCommented:
I did not understand it completely, But you can always create a temporary table. It goes in this way.

Select Name, Order = Identity(Int,1,1) Into ##temp From T1.

Select * From ##Temp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.