CREATE FUNCTION dbo.SubTypesMatch(@ARoomNumber INTEGER, @ASubTypeList VARCHAR (100), @Operator TINYINT)
RETURNS BIT AS
/*
    Created by Jacob Pedersen 2006-07-17

    Last Changed:
    N/A

    TBooleanFunction = (bfAND, bfOR, bfXOR, bfNOT, bfNAND, bfNOR, bfXNOR);  // http://searchsmb.techtarget.com/sDefinition/0,,sid44_gci213512,00.html

    bfAND - Products which belong to ALL specified hotels
    bfOR - Products which belong to ANY of the specified hotels
    bfNOT - Products which does NOT belong to any of hotel specified hotels

*/
BEGIN
  DECLARE @Return BIT
  DECLARE @SubTypeCount INT
  DECLARE @SubRoomCount INT

  SET @Return = 0

  SELECT @SubTypeCount = COUNT(*) FROM DBO.iter_intlist_to_table_No_Dummy(@ASubTypeList)

  SELECT @SubRoomCount =  COUNT(*) from RoomRoomSubTypeXTab rr 
  INNER join DBO.iter_intlist_to_table_No_Dummy(@ASubTypeList) s ON rr.SubTypeNumber = s.number
  AND RoomNumber = @ARoomNumber 

  IF @Operator = 0 AND @SubRoomCount = @SubTypeCount --bfAND
	SET @Return = 1
  IF @Operator = 1 AND @SubRoomCount > 0 --bfOr
	Set @Return = 1
  IF @Operator = 3 AND @SubRoomCount = 0 -- bfNot
	SET @Return = 1


  RETURN @Return
END

