Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Autoincrement field in MS SQL 2005 select

Posted on 2014-02-26
2
Medium Priority
?
787 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
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

927 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