SELECT DISTINCT D.OPRID ,A.EMPLID ,A.PY_TAX_YEAR ,A.COMPANY FROM PS_PY_SS_RL_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 = 'R') OR (A.PY_TAX_YEAR < 2017 AND A.TAXFORM_ID = 'R' AND EXISTS ( SELECT 'X' FROM PS_PY_YE_CONS_MRQ C WHERE C.EMPLID = A.EMPLID AND C.YE_CONSENT_CURRENT = 'C') ) OR (A.TAXFORM_ID = 'V' AND EXISTS ( SELECT 'X' FROM PS_PY_YE_CONS_MRQ C1 WHERE C1.EMPLID = A.EMPLID AND C1.YE_CONSENT_CURRENT = 'C')))
|