Solved

Autoincrement field in MS SQL 2005 select

Posted on 2014-02-26
2
768 Views
Last Modified: 2014-02-26
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?
0
Comment
Question by:LuckyLucks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 39890332
select Name, rn = row_number() over ( order by Name) from T1;
0
 

Expert Comment

by:bharathmosur
ID: 39890408
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

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question