Solved

Add column with number of row

Posted on 2011-09-09
2
400 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
2 Comments
 
LVL 21

Accepted Solution

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

Greg
0
 
LVL 59

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now