I am trying to create a saved process that returns all updated records.
My update request:
UPDATE BatchItems SET [Status] = 'Processing' WHERE [Status] = 'Queued'
I just donβt know how to return these specific entries.
You can use OUTPUT INSERTED.[cols] to select the rows that the statement changed.
OUTPUT INSERTED.[cols]
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 are using SQL Server 2005 or higher, you can use the OUTPUT clause.
http://msdn.microsoft.com/en-us/library/ms177564(v=SQL.90).aspx
update BatchItems set Status = 'Processing' output inserted.* where Status = 'Queued'