CREATE PROCEDURE dbo.OnlineHallFilterOK_New @AStartDate datetime, @AEndDate datetime, @AOnlineBookTypeNumber INT, @ANumberOfHalls INT, @AAvailableHalls INT , @AResult BIT OUTPUT AS

--Created AV 2007 0420

-- last changed param @Aonlinebooktypenumber is not the key anymore
-- sidst rettet: 2007 0816 fjernet et = tegn ved sammenligning af minavailable units

--NOTE: The procedure returns TRUE if a HallFilter exists on each day in the period and the Max and Min Rooms Avail value is approved against the input parameters
DECLARE @TempDate DateTime
DECLARE @OnlineBookTypeNumberID INT
SELECT @OnlineBookTypeNumberID = OnlineBookTypeNumber FROM OnlineBookType WITH (NOLOCK) WHERE Number = @AOnlineBookTypeNumber

SET @AResult = 1
SET @TempDate = @AStartDate

WHILE @TempDate <=@AEndDate
BEGIN
  IF NOT EXISTS (SELECT DateStamp FROM RoomBookingStatusYield WITH (NOLOCK)  INNER JOIN Yield WITH (NOLOCK) ON Yield.YieldNumber = RoomBookingStatusYield.OnlineYieldFilterHall AND Yield.FilterTypeNumber = 2 
  INNER JOIN YieldOnlineBookTypeXTab WITH (NOLOCK) ON Yield.YieldNumber = YieldOnlineBookTypeXTab.FK_YieldNumber AND YieldOnlineBookTypeXTab.FK_OnlineBookTypeNumber = @OnlineBookTypeNumberID
  AND ISNULL(YieldOnlineBookTypeXTab.MinAvailableUnits,0) <@AAvailableHalls AND (MaxUnitsReservation >=@ANumberOfHalls OR ISNULL(MaxUnitsReservation,0) = 0)
  WHERE CONVERT(VARCHAR(8),DateStamp,112) = CONVERT(VARCHAR(8),@TempDate,112))
  BEGIN
    SET @AResult = 0
    BREAK
  END
  SELECT @TempDate = DATEADD(DAY, 1, @TempDate)
END


