SELECT DISTINCT D.OPRID ,A.EMPLID ,A.PY_TAX_YEAR ,A.COMPANY FROM PS_PY_SS_CAN_GDE A , PS_PY_YEOPT_CO_CAN B , PSOPRDEFN D WHERE A.YE_FORM_VIEWING_DT <= %CurrentDateIn AND A.PY_SLIP_FINAL_PRT = 'Y' AND A.COMPANY = B.COMPANY AND A.PY_TAX_YEAR = B.PY_TAX_YEAR AND ( (A.PY_TAX_YEAR >= 2017 AND A.TAXFORM_ID = 'T') OR (A.PY_TAX_YEAR < 2017 AND A.TAXFORM_ID = 'T' AND EXISTS ( SELECT 'X' FROM PS_PY_YE_CONS_CAN C WHERE C.EMPLID = A.EMPLID AND C.YE_CONSENT_CURRENT = 'C')) OR (A.TAXFORM_ID = 'A' AND A.PY_TAX_YEAR >= 2022) OR (A.PY_TAX_YEAR < 2022 AND A.TAXFORM_ID = 'A' AND EXISTS ( SELECT 'X' FROM PS_PY_YE_CONS_CAN C1 WHERE C1.EMPLID = A.EMPLID AND C1.YE_CONSENT_CURRENT = 'C')) )
|