SELECT DISTINCT A.EMPLID ,C.COUNTRY ,'Y' FROM PS_PERSON A ,PS_JOB B ,PS_PAYGROUP_TBL C WHERE B.EMPLID=A.EMPLID AND B.EFFDT= ( SELECT MAX (G.EFFDT) FROM PS_JOB G WHERE G.EMPLID=B.EMPLID AND G.EMPL_RCD=B.EMPL_RCD AND G.EFFDT<= %CurrentDateIn) AND C.COMPANY=B.COMPANY AND C.PAYGROUP=B.PAYGROUP AND C.EFFDT= ( SELECT MAX (H.EFFDT) FROM PS_PAYGROUP_TBL H WHERE H.COMPANY=B.COMPANY AND H.PAYGROUP=B.PAYGROUP AND H.EFFDT<= %CurrentDateIn) AND ( (C.COUNTRY='USA' AND EXISTS ( SELECT 'x' FROM PS_CHECK_YTD US WHERE US.EMPLID=A.EMPLID AND US.COMPANY=B.COMPANY)) OR (C.COUNTRY='CAN' AND EXISTS ( SELECT 'x' FROM PS_CAN_CHECK_YTD US WHERE US.EMPLID=A.EMPLID AND US.COMPANY=B.COMPANY)))
|