#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Help writing a cursor to sequence duplicate entries


    I have a table:
    Inc Project
    1 ProjectA
    2 ProjectA
    3 ProjectA
    1 ProjectB
    2 ProjectB
    1 ProjectC

    And I to achieve this:
    Inc Project
    1 ProjectA_1
    2 ProjectA_2
    3 ProjectA_3
    1 ProjectB_1
    2 ProjectB_2
    1 ProjectC_1

    I think a cursor would work great here, especially because I only have 300 rows of data to process.
    Thanks
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,244
    Rep Power
    4279
    you don't even need a cursor
    Code:
    UPDATE daTable
       SET project = project + '_' + inc
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    Paris Uppland
    Posts
    2,385
    Rep Power
    391
    Code:
    update t
       set project = project +  '_' + cast(inc as varchar(10))

IMN logo majestic logo threadwatch logo seochat tools logo