CREATE FUNCTION dbo.MCC_GetPDAMaintenanceCategoryGroups ( @HotelNumber int =-1) RETURNS @Result TABLE (TaskName VARCHAR(100), TaskDescription VARCHAR(100)) AS
BEGIN
  INSERT INTO @Result
	
  SELECT DISTINCT CategoryGroup.GText AS TaskName, ISNULL(CategoryGroup.GDescription, '') AS TaskDescription
  FROM CategoryGroup WITH (NOLOCK) 
  INNER JOIN CategoryGroupXTabCustomer WITH (NOLOCK) ON CategoryGroupXTabCustomer.GroupNumber = CategoryGroup.GroupNumber 
  WHERE ISNULL(CategoryGroupXTabCustomer.CustomerNumber, -1)  IN (-1, (SELECT CustomerNumber FROM Customer WITH (NOLOCK) WHERE HotelNumber = @HotelNumber AND CustomerTypeNumber = 7 AND ISNULL(Customer.MarkAsDeleted, 0) = 0 ))  
  AND CategoryGroup.Type = 19 -- 19 = Maintenance 
  ORDER BY CategoryGroup.GText

  RETURN
END