Increment columns with same name

  • I actually need to update an existing column with incremental numbers..as shown... Can you help me to write a script to get the following output.

    COLA COLB

    1 Username1

    2 Username2

    3 Username3

    N UsernameN

    Thank you...

  • DBA_SQL (1/18/2012)


    I actually need to update an existing column with incremental numbers..as shown... Can you help me to write a script to get the following output.

    COLA COLB

    1 Username1

    2 Username2

    3 Username3

    N UsernameN

    Thank you...

    you mean like this?

    UPDATE YourTable

    SET COLB = 'Username' + CONVERT(varchar,COLA)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Well..I just tried and got the result... Thanks for response..

    update tablename

    set

    columnname = 'Username' + substring(convert(varchar(32), ID), 1, 10)

Viewing 3 posts - 1 through 2 (of 2 total)

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