Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Sequential Number to a repeating record

Status
Not open for further replies.

mrodonis

Programmer
Jun 26, 2007
5
thread183-859372

The original thread does what I need when the repeated record is an Integer, but I need this when the record is a varchar. For example, I have the following client_tag field, where I need to add a sequential number for each record that is the identical, restarting the sequence for each new Client_Tag.

Client_Tag Seq (Need to add this column)

AA00001224 1
AA00001224 2
AA00001224 3
BB00001234 1
CC00001233 1
CC00001233 2

I appreciate any assistance with this.
Thanks!
 
Try something like this:

Code:
select
    Client_Tag,
    ROW_NUMBER() OVER(PARTITION BY Client_Tag ORDER BY Client_Tag) AS Seq
from MyTable

Hope this helps.


Imoveis em Guarulhos
 
Imex,
Thanks so much, that worked perfectly!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top