SELECT DISTINCT A.EMPLID ,B.COMPANY ,D.ACA_ALE_MEMBER ,D.ACA_ONLINE_OPT FROM PS_PERSON A , PS_JOB B , PS_ACA_CMPY_TBL C , PS_ACA_FORM_OPTS D WHERE B.EMPLID=A.EMPLID AND B.EFFDT = ( SELECT MAX (B1.EFFDT) FROM PS_JOB B1 WHERE B1.EMPLID = B.EMPLID AND B1.EMPL_RCD = B.EMPL_RCD AND B1.COMPANY = B.COMPANY AND ((B1.EFFDT <= %CurrentDateIn) OR (B.EFFDT > %CurrentDateIn AND %CurrentDateIn < ( SELECT MIN(J2.EFFDT) FROM PS_JOB J2 WHERE J2.EMPLID = B.EMPLID AND J2.EMPL_RCD = B.EMPL_RCD AND J2.COMPANY = B.COMPANY) ) )) AND B.EFFSEQ = ( SELECT MAX(B2.EFFSEQ) FROM PS_JOB B2 WHERE B2.EMPLID = B.EMPLID AND B2.EMPL_RCD = B.EMPL_RCD AND B2.EFFDT = B.EFFDT AND B2.COMPANY = B.COMPANY) AND C.COMPANY=B.COMPANY AND C.EFFDT = ( SELECT MAX (C1.EFFDT) FROM PS_ACA_CMPY_TBL C1 WHERE C1.COMPANY = C.COMPANY AND C1.EFFDT <= %CurrentDateIn) AND C.ACA_ALE_MEMBER = D.ACA_ALE_MEMBER AND D.ACA_ONLINE_OPT = 'Y' AND D.ACA_CALENDAR_YEAR = ( SELECT MAX(D1.ACA_CALENDAR_YEAR) FROM PS_ACA_FORM_OPTS D1 WHERE D1.ACA_ALE_MEMBER = D.ACA_ALE_MEMBER AND %DateIn((%NumtoChar(D1.ACA_CALENDAR_YEAR) %Concat '-01-01')) <= %CurrentDateIn)
|