DECLARE @RC int
DECLARE @ReferenceNumber int
DECLARE @GuestNumber int
DECLARE @GuestArrivalDate char(8)
DECLARE @GuestArrivalTime char(5)
DECLARE @GuestDepartureDate char(8)
DECLARE @GuestDepartureTime char(5)
DECLARE @GuestAdults int
DECLARE @GuestChildren1 int
DECLARE @GuestChildren2 int
DECLARE @GuestPrice money
DECLARE @GuestTotalPrice money
DECLARE @GuestProductNumber int
DECLARE @ArrivalDate char(8)
DECLARE @ArrivalTime char(5)
DECLARE @DepartureDate char(8)
DECLARE @DepartureTime char(5)
DECLARE @Adults int
DECLARE @Children1 int
DECLARE @Children2 int
DECLARE @Price money
DECLARE @TotalPrice money
DECLARE @UpdateMainRes int
DECLARE @WasUpdated smallint

DECLARE TmpCursor CURSOR FOR
  SELECT ReferenceNumber, GuestNumber
  FROM RESERVATIONS (NOLOCK)
  WHERE (1=1)
    --AND Status <= 5
	--AND DepartureDate >= '20200101'
OPEN TmpCursor
FETCH NEXT FROM TmpCursor INTO @ReferenceNumber, @GuestNumber
WHILE (@@FETCH_STATUS<>-1)
BEGIN
  EXECUTE @RC = [dbo].[UpdateArrivalAndDeparture] 
     @ReferenceNumber
    ,@GuestNumber
    ,@GuestArrivalDate OUTPUT
    ,@GuestArrivalTime OUTPUT
    ,@GuestDepartureDate OUTPUT
    ,@GuestDepartureTime OUTPUT
    ,@GuestAdults OUTPUT
    ,@GuestChildren1 OUTPUT
    ,@GuestChildren2 OUTPUT
    ,@GuestPrice OUTPUT
    ,@GuestTotalPrice OUTPUT
    ,@GuestProductNumber OUTPUT
    ,@ArrivalDate OUTPUT
    ,@ArrivalTime OUTPUT
    ,@DepartureDate OUTPUT
    ,@DepartureTime OUTPUT
    ,@Adults OUTPUT
    ,@Children1 OUTPUT
    ,@Children2 OUTPUT
    ,@Price OUTPUT
    ,@TotalPrice OUTPUT
    ,@UpdateMainRes
    ,@WasUpdated OUTPUT
  FETCH NEXT FROM TmpCursor INTO @ReferenceNumber, @GuestNumber
END
CLOSE TmpCursor
DEALLOCATE TmpCursor


