CREATE FUNCTION dbo.NumberOfRoomsForHotel (@AHotelCustomerNumber INT) RETURNS INTEGER AS
BEGIN
  DECLARE @Res INT
  SELECT @Res = COUNT(*) 
  FROM Rooms WITH (NOLOCK) 
  INNER JOIN RoomTypes WITH (NOLOCK) ON RoomTypes.RoomTypeNumber = Rooms.RoomTypeNumber
  INNER JOIN Customer WITH (NOLOCK) ON Customer.HotelNumber = RoomTypes.HotelNumber
    AND Customer.CustomerTypeNumber = 7
    AND (Customer.HotelNumber>0 OR Customer.LocalHotel=1)
    AND ISNULL(Customer.MarkAsDeleted, 0) = 0
	AND Customer.CustomerNumber = @AHotelCustomerNumber

  RETURN @Res
END