



CREATE PROCEDURE DBO.OrderBookDeleteIfAllValueZeo @CustomerNumber int AS
SET NOCOUNT ON

-- rettet d. 29/10 af Klaus Stenå

SET NOCOUNT ON

Declare @CustomerNumberOrdreBook int

Declare @SegmentNumber int
Declare @DateForValue Char(8)
Declare @TurnoverRooms money
Declare @NumberOfNightRooms int
Declare @NumberOfPaxRooms int
Declare @NumberOfStaysRooms int
Declare @NumberOfCXLRooms int
Declare @NumberOfNoShowRooms int

Declare @TurnoverDaymeetings money
Declare @NumberOfPaxDaymeetings int
Declare @NumberOfStaysDaymeetings int

Declare @TurnoverHalls money
Declare @NumberOfHalls int
Declare @NumberOfPaxHalls int

Declare @TurnoverRestaurant int

Declare @TurnoverOther int

Declare OrdreBookCursor Cursor Forward_Only For
Select CustomerNumber, SegmentNumber, DateForValue, TurnoverRooms, NumberOfNightRooms, NumberOfPaxRooms, NumberOfStaysRooms, NumberOfCXLRooms, NumberOfNoShowRooms,
       TurnoverDaymeetings, NumberOfPaxDaymeetings, NumberOfStaysDaymeetings, TurnoverHalls, NumberOfHalls, NumberOfPaxHalls, TurnoverRestaurant, TurnoverOther  From CustomerOrdreBook WITH (NOLOCK)  where CustomerNumber=@CustomerNumber
Open OrdreBookCursor
Fetch Next From OrdreBookCursor
Into @CustomerNumberOrdreBook, @SegmentNumber, @DateForValue, @TurnoverRooms, @NumberOfNightRooms, @NumberOfPaxRooms, @NumberOfStaysRooms, @NumberOfCXLRooms, @NumberOfNoShowRooms,
       @TurnoverDaymeetings, @NumberOfPaxDaymeetings, @NumberOfStaysDaymeetings, @TurnoverHalls, @NumberOfHalls, @NumberOfPaxHalls, @TurnoverRestaurant, @TurnoverOther
  
While (@@FETCH_STATUS <> -1)
begin
  if (@TurnoverRooms=0 AND @NumberOfNightRooms=0 AND @NumberOfPaxRooms=0 AND @NumberOfStaysRooms=0 AND @NumberOfCXLRooms=0 AND @NumberOfNoShowRooms=0 AND
     @TurnoverDaymeetings=0 AND @NumberOfPaxDaymeetings=0 AND @NumberOfStaysDaymeetings=0 AND @TurnoverHalls=0 AND @NumberOfHalls=0 AND
     @NumberOfPaxHalls=0 AND @TurnoverRestaurant=0 AND @TurnoverOther=0)
  begin
    Delete From CustomerOrdreBook where(CustomerNumber=@CustomerNumber and SegmentNumber=@SegmentNumber and DateForValue=@DateForValue)
  end

  Fetch Next From OrdreBookCursor 
  Into @CustomerNumberOrdreBook, @SegmentNumber, @DateForValue, @TurnoverRooms, @NumberOfNightRooms, @NumberOfPaxRooms, @NumberOfStaysRooms, @NumberOfCXLRooms, @NumberOfNoShowRooms,
         @TurnoverDaymeetings, @NumberOfPaxDaymeetings, @NumberOfStaysDaymeetings, @TurnoverHalls, @NumberOfHalls, @NumberOfPaxHalls, @TurnoverRestaurant, @TurnoverOther
end
 
Close OrdreBookCursor
Deallocate OrdreBookCursor

