sql - Update with Priority -


here request:

update  top (1) innerportal.feedback.queuefeedback set busy = 1, busyby = @uid output inserted.* (         accountcode = @account ,         (done null or done = 0) ,          (busy null or busy = 0) ,          ((datepart(hour, dateadd(hour, utc, @utcnow)) >= 9 ) ,         (datepart(hour, dateadd(hour, utc, @utcnow)) <= 20)) ) 

it gets first founded "non busy" record key field accountcode.
if record not found request returns nothing.
next have ordered list of accountcode , target release special logic:
need create loop in request.
first accountcode list , try update.

  • if success - stop , return output inserted.*
  • if update not successful request second entry accounts list , try update again.

if loop on , nothing updated - output inserted.* returns nothing (like now).
possible release in single request? thanks!

update top (1) innerportal.feedback.queuefeedback

set busy = 1, busyby = @uid output inserted.*  innerportal.feedback.queuefeedback join account    on accountcode = account.id  , accountcode = @account   , (done null or done = 0)   , (busy null or busy = 0)   , (     (datepart(hour, dateadd(hour, utc, @utcnow)) >= 9 )         , (datepart(hour, dateadd(hour, utc, @utcnow)) <= 20) ) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -