CREATE PROCEDURE DBO.LockedReservationCleanUp AS
SET NOCOUNT ON
/*
    Created By: Jacob Pedersen 20050405

    Last Updated:	

    20050609 JP: do not touch transaction isolation level

    NOTE: This rutine is used to cleanup committed rows in LockedReservation table. No idea why they are committed since transaction never is.
*/

--SET TRANSACTION ISOLATION LEVEL READ COMMITTED

DECLARE
@ReferenceNumber INT,
@GuestNumber SMALLINT,
@UserIDNumber INT,
@LockedByFunction TINYINT

DECLARE #LockedCur CURSOR LOCAL FAST_FORWARD FOR

--  SELECT ReferenceNumber, GuestNumber, UserIDNumber, LockedByFunction FROM LockedReservations(READPAST)
  SELECT ReferenceNumber, GuestNumber, UserIDNumber, LockedByFunction FROM LockedReservations WITH (READPAST,READCOMMITTED)

OPEN #LockedCur

FETCH NEXT FROM #LockedCur
INTO @ReferenceNumber, @GuestNumber, @UserIDNumber, @LockedByFunction

WHILE (@@FETCH_STATUS <> -1)
BEGIN
  DELETE FROM LockedReservations WHERE ReferenceNumber=@ReferenceNumber AND GuestNumber=@GuestNumber AND UserIDNumber=@UserIDNumber AND LockedByFunction=@LockedByFunction

  FETCH NEXT FROM #LockedCur
  INTO @ReferenceNumber, @GuestNumber, @UserIDNumber, @LockedByFunction
END

CLOSE #LockedCur
DEALLOCATE #LockedCur

--SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

