mssql has a lot of "tricks" associated with CTE's. Using the OUTPUT clause on updates is one of them.. Here's some queue code using a cte to grab the top one by queued date.
DECLARE @Queue TABLE (QueueID INT)
WITH q AS (
SELECT TOP (1) QueueID, StatusID, ModifiedDate
FROM worker.Queue WITH (ROWLOCK, READPAST)
WHERE StatusID=(SELECT TOP 1 s.StatusID FROM worker.Status s (NOLOCK) WHERE s.[Status] IN ('Queued'))
ORDER BY QueueDate ASC
)
UPDATE q SET
StatusID=(SELECT s.StatusID FROM worker.Status s (NOLOCK) WHERE s.[Status]='Processing'),
StatusMessage='New Process',
ModifiedDate=GETDATE()
OUTPUT INSERTED.QueueID INTO @Queue