CREATE FUNCTION dbo.IsDayRoom (@ArrivalDate CHAR(8), @ArrivalTime CHAR(5), @DepartureDate CHAR(8), @DepartureTime CHAR(5), @CurrentDate CHAR(8))
RETURNS BIT AS  
BEGIN 

DECLARE @Result BIT
SET @Result = 0

IF @ArrivalDate = @DepartureDate
  SET @Result = 1
ELSE IF @DepartureDate = @CurrentDate
BEGIN
  DECLARE @DayroomsLaterThanTime CHAR (5)
  SELECT @DayroomsLaterThanTime=ISNULL(KeyValue, '23:59') FROM dbo.HotelSetup WITH (NOLOCK) WHERE SearchKey='DayroomsLaterThanTime'

  IF @DepartureTime>@DayroomsLaterThanTime AND @DayroomsLaterThanTime<'23:59'
    SET @Result = 1
END

RETURN @Result

END

