looks like no problem...you simply need to add that additional check to your update...
something like this looks correct to me, base don what you posted so far:
this would be the query that should show you everything in the current matching criteria i think you've provided:
SELECT *
FROM AGS_Hands_InProcess
WHERE Win is NULL -- protection.
AND ts_started < DATEADD(hh, -1, GETDATE())
and cuserid IN ( select
cuserid
from UserBalanceAdjustments
where ReasonForAdjustment like 'ADJ AGS%'
and AGS_Hands_InProcess .transactiontime>dateadd(ww,-1,getdate()) -- for efficiency, limit the time window, e.g. a week
)
and this would be the all inclusive update:
UPDATE AGS_Hands_InProcess SET
Win= 5, -- the value from the matching Adjustement
ts= getdate() -- the timestamp of last action on this hand
WHERE Win is NULL -- protection.
AND ts_started < DATEADD(hh, -1, GETDATE())
and cuserid IN ( select
cuserid
from UserBalanceAdjustments
where ReasonForAdjustment like 'ADJ AGS%'
and AGS_Hands_InProcess.transactiontime>dateadd(ww,-1,getdate()) -- for efficiency, limit the time window, e.g. a week
)
Lowell