UPDATE @result
SET selectiondate=eventdatetime
FROM @result r
INNER JOIN (
SELECT r.id, MAX(h.EventDateTime) eventdatetime
FROM @result r
LEFT JOIN statehistory h WITH (NOLOCK) ON h.id = r.id AND h.eventid = @CONST_SelectedEvent
GROUP BY r.id
) d ON d.id=r.id
No comments:
Post a Comment