Quantcast
Channel: Answers for "Stored Procedure to Select/Update multiple records"
Viewing all articles
Browse latest Browse all 8

Answer by Matt Whitfield

$
0
0

You could just select the records you want into a table variable:

DECLARE @targetRowIDs TABLE (rowID int NOT NULL)
INSERT INTO @targetRowIDs (rowID)
SELECT ID FROM MSG_Q WITH (updlock, readpast) WHERE MSG_Q.status=0
SELECT TOP 1 * FROM MSG_Q WHERE MSG_Q.id IN (SELECT rowID FROM @targetRowIDs)
UPDATE MSG_Q SET status=1 WHERE id IN (SELECT rowID FROM @targetRowIDs)

Note that you'll have to modify the top select to select the rows you want.


Viewing all articles
Browse latest Browse all 8

Trending Articles