



CREATE PROCEDURE DBO.UpdateSplitBillOnReservations AS
SET NOCOUNT ON
-- Sidst rettet af Klaus Stenå Nielsen d. 14/3-2002

Declare @CurrentDateStr char(8)

Declare @SplitBillNumber int
Declare @ReferenceNumber int

SELECT @CurrentDateStr = SYSTEMDATE FROM System WITH (NOLOCK)  WHERE NUMBER = 1  -- Only one record


      Declare ReservationCur Cursor Forward_Only For
      SELECT
         RESERVATIONS.ReferenceNumber, 
         RESERVATIONS.SplitBill
      from Reservations WITH (NOLOCK) 
      where SplitBill>0 and GuestNumber=0 and ((Convert(char,ArrivalDate,112)>=@CurrentDateStr) OR ((Convert(char,ArrivalDate,112)>@CurrentDateStr) AND (Convert(char,DepartureDate,112)<=@CurrentDateStr)))

      open ReservationCur
      Fetch next From ReservationCur into @ReferenceNumber, @SplitBillNumber

While (@@Fetch_Status <> -1)
begin
      Update Reservations SET
        SplitBill = @SplitBillNumber
      where ReferenceNumber=@ReferenceNumber and GuestNumber>0

      Fetch next From ReservationCur into @ReferenceNumber, @SplitBillNumber
end

Close ReservationCur
Deallocate ReservationCur

