CREATE PROCEDURE DBO.FixReservationGroup @HotelNumber INT, @ReferenceNumber INT AS
SET NOCOUNT ON
/*
    DEPENDENCIES: UpdateArrivalAndDeparture2, UpdateArrivalAndDeparture

    Created by Jacob Pedersen 09-08-2002

    Last updated: N/A

    NOTE: - This routine fixes all reservations in a group

*/

UPDATE ReservationMain SET HotelNumber=0 WHERE HotelNumber IS NULL

DECLARE @GuestNumber INT

DECLARE #ReadResCur CURSOR FORWARD_ONLY FOR

  SELECT GuestNumber
  FROM Reservations WITH (NOLOCK) INNER JOIN ReservationMain WITH (NOLOCK) ON ReservationMain.ReferenceNumber=Reservations.ReferenceNumber WHERE Reservations.ReferenceNumber=@ReferenceNumber AND HotelNumber=@HotelNumber
  ORDER BY GuestNumber DESC-- 0 must be last!!!

OPEN #ReadResCur

FETCH NEXT FROM #ReadResCur
INTO @GuestNumber

WHILE (@@FETCH_STATUS <> -1)
BEGIN
  PRINT 'Fixing res:'+convert (varchar, @referencenumber)+'/'+convert (varchar, @guestnumber)
  EXEC UpdateArrivalAndDeparture2 @ReferenceNumber, @GuestNumber, 0

  FETCH NEXT FROM #ReadResCur
  INTO @GuestNumber
END

CLOSE #ReadResCur
DEALLOCATE #ReadResCur

