Marilyn
2009-09-21 21:01:01 UTC
Hi,
Is it possible to use Row_Number() function in an UPDATE statement?
The following code works fine when I use a SELECT statement:
SELECT cokey, chkey, NLAYERS, ROW_NUMBER() OVER(PARTITION BY cokey ORDER BY
chkey) AS 'LYRNO' FROM chorizon
But what I need is to update the LYRNO column to store the row numbers
generated by the SELECT statement. So I have the following client-side T-SQL
code:
UPDATE chorizon SET LYRNO = (SELECT ROW_NUMBER() OVER (PARTITION BY cokey
ORDER by chkey) AS 'LYRNO' FROM chorizon)
However, I'm getting this error: "Subquery returned more than 1 value.
This is not permitted..."
Any assistance is greatly appreciated.
Is it possible to use Row_Number() function in an UPDATE statement?
The following code works fine when I use a SELECT statement:
SELECT cokey, chkey, NLAYERS, ROW_NUMBER() OVER(PARTITION BY cokey ORDER BY
chkey) AS 'LYRNO' FROM chorizon
But what I need is to update the LYRNO column to store the row numbers
generated by the SELECT statement. So I have the following client-side T-SQL
code:
UPDATE chorizon SET LYRNO = (SELECT ROW_NUMBER() OVER (PARTITION BY cokey
ORDER by chkey) AS 'LYRNO' FROM chorizon)
However, I'm getting this error: "Subquery returned more than 1 value.
This is not permitted..."
Any assistance is greatly appreciated.