CREATE FUNCTION [dbo].[NumberOfRoomsForHotelNumber] (@AHotelNumberCSV VARCHAR(500), @ASubRooms BIT) RETURNS INTEGER AS
BEGIN
  DECLARE @Res INT
  SELECT @Res = COUNT(*) 
  FROM Rooms WITH (NOLOCK) 
  INNER JOIN RoomTypes WITH (NOLOCK) ON RoomTypes.RoomTypeNumber = Rooms.RoomTypeNumber AND 
	(@AHotelNumberCSV = '' OR RoomTypes.HotelNumber IN (SELECT DISTINCT Number FROM iter_intlist_to_table(@AHotelNumberCSV))) AND
	((ISNULL(RoomTypes.ParentRoomtypeNumber, 0) = 0 AND @ASubRooms = 0) OR
	 (ISNULL(RoomTypes.ParentRoomtypeNumber, 0) > 0 AND @ASubRooms = 1))   

  RETURN @Res
END


