?
Solved

numbering repetaed records 12 123 1 1234 etc sql ms 2005

Posted on 2008-10-16
5
Medium Priority
?
205 Views
Last Modified: 2010-03-19
I have a table with n records (1 field each) I nee an sqk query that will order them by field and add a consecutive number to each repeted record starting from 1 then 2 then 3 ..until the next different record(field) is reached abd star againnwith 1,2 123,1, etc

Ex
John 1
John 2
Mike 1
Sam  1
Sam 2
Sam 3
0
Comment
Question by:robrodp
[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
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 2000 total points
ID: 22736714
This should do:

select YourField, row_number() over (partition by YourField order by yourField) from YourTable

0
 

Author Comment

by:robrodp
ID: 22736801
select email row_number() over (partition by email order by email) from icrea

I get this error:

Incorrect syntax near ')'.
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22736861
you forgot the comma between email and row_number()
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22736868
and the reason it is giving an error is because it thinks you are trying to alias email as row_number
0
 

Author Comment

by:robrodp
ID: 22736910
Got it....

Sorry
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

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