SELECT
  AT.AttendanceTypeID,
  TRIM(AT.AppointmentType) AS AppointmentType
FROM
  taProducts AS PR,
  tbAppointmentTypes AS AT
    LEFT JOIN taAttendanceExclusion AS AE ON ((AE.ProductID = @nProductID) AND (AE.AttendanceTypeID = AT.AttendanceTypeID))
WHERE
  (PR.ProductID = @nProductID) AND
  (AT.ProductCategory = PR.ProductCategory) AND
  (AT.IsService = 1) AND
  (AT.IsActive = 1) AND
  (TRIM(AT.AppointmentType) <> '') AND
  ((AE.ProductID IS NULL) OR (AT.AlwaysAllowed = 1))
ORDER BY
  AT.AppointmentType