Here is the request:
UPDATE TOP (1) InnerPortal.Feedback.QueueFeedback
SET Busy = 1, BusyBy = @uid
Output inserted.*
WHERE (
AccountCode = @account and
(Done is null or Done = 0) and
(Busy is NULL or Busy = 0) and
((DATEPART(hour, DATEADD(HOUR, Utc, @utcNow)) >= 9 ) and
(DATEPART(hour, DATEADD(HOUR, Utc, @utcNow)) <= 20))
)
It gets first founded "non busy" record where the key field is AccountCode
.
If record not found request returns nothing.
Next I have an ordered list of AccountCode
and the target is to release a special logic:
I need to create something like a loop in this request.
It will get first AccountCode
from list and try to update.
- if success - it will stop and will return
Output inserted.*
- If update was not successful request will get second entry from my accounts list and try to update again.
If the loop is over and nothing was updated - Output inserted.*
returns nothing (like now).
Is it possible to release in single request? Thanks!