How to add a Counter for Duplicate Entries

  • Does anyone know how I can create Column2 data using SQL?

    Column1 Column2

    A 1

    A 1

    B 2

    B 2

    B 2

    C 3

  • Sorry I got column2 data wrong. I'm actually trying to get the following data values in Column2:

    Column1 Column2

    A 1

    A 2

    B 1

    B 2

    B 3

    C 1

    etc. ......

    Thanks.

  • There is a function called ROW_NUMBER that should be able to help you out.

    There was a good article on here not long ago about ROW_NUMBER. If I can find it, I'll post the link. In the meantime, try looking it up in BOL and see if that helps.

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

  • Lo and behold, the article was in my briefcase: http://www.sqlservercentral.com/articles/T-SQL/66512/

    Give it a try. After reading the article, I experimented with it a bit, and got it to work very much like what you're asking.

    Hope this helps!

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply