SQL Update with row_number()
Posted
by
user609511
on Stack Overflow
See other posts from Stack Overflow
or by user609511
Published on 2012-11-30T16:14:59Z
Indexed on
2012/12/01
17:04 UTC
Read the original article
Hit count: 246
sql-server-2008
|sql-update
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
© Stack Overflow or respective owner