Solved

Add column with number of row

Posted on 2011-09-09
2
406 Views
Last Modified: 2012-05-12
I would like to add a column with the number of the row, i.e. the first row is 1, second is 2, third 3 etc.
How can I do that?
0
Comment
Question by:johnkainn
[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 21

Accepted Solution

by:
JestersGrind earned 250 total points
ID: 36514343
Use ROW_NUMBER() OVER(YourColumn)

Greg
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36514378
I agree with Greg. For some clarity, please see this article:
http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/A_1555-Analytical-SQL-Where-do-you-rank.html

Please credit Greg for the solution, but you would first need to generate the row number based on some column that identifies your row as first in sort -- syntax is more precisely:
ROW_NUMBER() OVER(ORDER BY your_sort_column) RN

Open in new window


what you may be asking for though is to add an IDENTITY column. If one is not already added, you can do this: ALTER TABLE YourTable ADD ID BIGINT IDENTITY(1,1);
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I find this data? 3 41
Database Owner 3 46
Trying to understand why my Index is so large 12 52
What is GIS method of Geometry data type? 6 36
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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