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

--Created AV 2006 1130

--Last Changed
-- 2007 0611use OnlineYieldFilterHall
-- 2007 0521 Hall filtertype number changed from 0 to 2 (Yield.FilterTypeNumbe)

--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

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
  WHERE CONVERT(VARCHAR(8),DateStamp,112) = CONVERT(VARCHAR(8),@TempDate,112)  AND MinRoomsAvail <= @AAvailableHalls AND MaxRoomsAvail >=@ANumberOfHalls)
  BEGIN
    SET @AResult = 0
    BREAK
  END
  SELECT @TempDate = DATEADD(DAY, 1, @TempDate)
END


