I'm trying to create a stored proc that returns all records that are updated.
My update query is this:
UPDATE BatchItems
SET [Status] = 'Processing'
WHERE [Status] = 'Queued'
I'm just not sure how to return those specific records.
You can use OUTPUT INSERTED.[cols]
to fetch rows the statement has modified.
UPDATE BatchItems
SET [Status] = 'Processing'
OUTPUT INSERTED.*
WHERE [Status] = 'Queued'
Example;
select 'Queued ' as status, 1 as id into #BatchItems
insert #BatchItems values ('Queued', 2)
insert #BatchItems values ('XXX', 3)
UPDATE #BatchItems
SET [Status] = 'Processing'
OUTPUT INSERTED.*
WHERE [Status] = 'Queued'
>>status id
>>Processing 2
>>Processing 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With