1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] SQL - how to update a column with each row value incremented by 1?

Discussão em 'Outras Linguagens' iniciado por Stack, Setembro 28, 2024 às 13:12.

  1. Stack

    Stack Membro Participativo

    For the selected rows in a column, how to update each row sequentially from the beginning to the end, with each row value incremented by 1 (or certain number). I know this can be done in excel in few seconds but I could figure out how to achieve in SQL server. For instance:

    customer id is NULL now update customer id with every row incremented by 1 (i.e. first row = 1, second row = 2, .....nth row = n)

    ship-to party customer id
    0002018092 NULL
    0002008127 NULL
    0002000129 NULL
    0002031592 NULL
    0002034232 NULL


    desired output

    ship-to party customer id
    0002018092 1
    0002008127 2
    0002000129 3
    0002031592 4
    0002034232 5


    Also, for the selected rows in a column, how to update each row with the row number? I know there is a row_number() function but didn't succeed in producing the desired result. for instance

    column A is NULL now update Column A with every row incremented by 1 (i.e. first row = row number 1, second row = row number 2, .....nth row = row number n)

    Any demonstration would be very helpful.thkans

    Continue reading...

Compartilhe esta Página