Update the 3 oldest records?

  • oops I meant to put this in the 2005 forum

  • wrong forum... but here is the answer, it uses some 2005 functionality though with the rownumber and over statements

    I need UPDLOCK and READPAST hints together. As explained here

    Tutorial

    So my statement should read.

    WITH Requests AS

    (

    Select *, ROW_NUMBER() OVER(ORDER BY RequestDate ASC) AS RowNum

    FROM ReportRequest_R2 WITH (UPDLOCK, READPAST)

    WHERE Status = 'O'

    )

    UPDATE Requests

    SET

    Status = 'P',

    StatusDate = getdate(),

    StatusDesc = 'Processing',

    LockGUID = @GUID,

    ProcessCount = ProcessCount + 1

    WHERE RowNum <= 3

Viewing 2 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply