• You need to have Status column in your task table, e.g. TaskID int not null, Status bit not null

    You can have code something like:

    DECLARE @TaskID int

    BEGIN TRAN

    SELECT @TaskID = MIN(TaskID) FROM TaskTable WITH (HOLDLOCK) WHERE Status=0

    UPDATE TaskTable

    SET Status=1

    WHERE TaskID=@TaskID

    -- Process the task....

    COMMIT TRAN