Reputation: 197
I have a MS SQL stored procedure (SP):
SELECT *
FROM tblA
WHERE stateID = 1
ORDER BY DateTime DESC
Still within the same SP, how do I update the stateID column for each row the SELECT statement returns? The SP still returns the rows from the SELECT statement.
Thanks!
Upvotes: 0
Views: 724
Reputation: 90
If you have a unique identifier within the results that are returned you could do this.
UPDATE tblA SET stateID = 2 WHERE download_id in (select download_id from FROM tblA
WHERE stateID = 1
ORDER BY DateTime DESC)
Upvotes: 1
Reputation: 176896
you can do like this , because this will return same rows
update tblA
set col = value
WHERE stateID = 1
Upvotes: 1