SQL Update with row_number()
- by user609511
i m using SQL Server 2008 R2.
i want to update my column CODE_DEST with increment number
CODE_DEST RS_NOM
null qsdf
null sdfqsdfqsdf
null qsdfqsdf
what i want:
CODE_DEST RS_NOM
1 qsdf
2 sdfqsdfqsdf
3 qsdfqsdf
i have try this:
update DESTINATAIRE_TEMP
set CODE_DEST = TheId FROM (SELECT Row_Number() OVER (ORDER BY [RS_NOM]) as TheId from DESTINATAIRE_TEMP)
not work because of )
and this
With DESTINATAIRE_TEMP As
(
SELECT
ROW_NUMBER() OVER (ORDER BY [RS_NOM] DESC) AS RN
FROM DESTINATAIRE_TEMP
)
UPDATE DESTINATAIRE_TEMP SET CODE_DEST=RN
because of union