Solved

Autoincrement field in MS SQL 2005 select

Posted on 2014-02-26
2
761 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

738 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