I have a local table variable in a stored procedure, containing a couple of columns; I need to update column 2 of each row with the result of a subquery based on the value of column 1 for that row.
Something like:
UPDATE @mytable
SET column2 = (SELECT ... FROM ... WHERE something = @mytable.column1)
But this doesn't seem to work, I get an error about @mytable being undefined.
What is the correct syntax for this query?
Have you tried using an ALIAS?
UPDATE temp
SET temp.column2 = (SELECT ... FROM ... WHERE something = temp.column1)
FROM @mytable temp
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.