SQL Update with row_number()

后端 未结 8 1798
执笔经年
执笔经年 2020-11-27 03:07

I want to update my column CODE_DEST with an incremental number. I have:

CODE_DEST   RS_NOM
null        qsdf
null        sdfqsdfqsdf
null        qsdfqsdf


        
相关标签:
8条回答
  • 2020-11-27 03:27

    One more option

    UPDATE x
    SET x.CODE_DEST = x.New_CODE_DEST
    FROM (
          SELECT CODE_DEST, ROW_NUMBER() OVER (ORDER BY [RS_NOM]) AS New_CODE_DEST
          FROM DESTINATAIRE_TEMP
          ) x
    
    0 讨论(0)
  • 2020-11-27 03:35

    Simple and easy way to update the cursor

    UPDATE Cursor
    SET Cursor.CODE = Cursor.New_CODE
    FROM (
      SELECT CODE, ROW_NUMBER() OVER (ORDER BY [CODE]) AS New_CODE
      FROM Table Where CODE BETWEEN 1000 AND 1999
      ) Cursor
    
    0 讨论(0)
提交回复
热议问题