SELECT PD.EMPLID , PD.NAME , JB2.DEPTID , JB2.JOBCODE ,0 ,0 FROM PS_PERSONAL_DATA PD LEFT OUTER JOIN ( SELECT * FROM PS_JOB JB1 WHERE JB1.EMPL_RCD = ( SELECT MIN(J2.EMPL_RCD) FROM PS_JOB J2 WHERE JB1.EMPLID = J2.EMPLID AND J2.EFFDT= ( SELECT MAX(J4.EFFDT) FROM PS_JOB J4 WHERE J4.EMPLID = J2.EMPLID AND J4.EMPL_RCD = J2.EMPL_RCD AND J4.EFFDT <= %CurrentDateIn) AND J2.EFFSEQ = ( SELECT MAX(J5.EFFSEQ) FROM PS_JOB J5 WHERE J5.EMPLID = J2.EMPLID AND J5.EMPL_RCD = J2.EMPL_RCD AND J5.EFFDT = J2.EFFDT )) AND JB1.EFFDT = ( SELECT MAX(EFFDT) FROM PS_JOB J3 WHERE J3.EMPLID=JB1.EMPLID AND J3.EMPL_RCD=JB1.EMPL_RCD AND J3.EFFDT <= %CurrentDateIn) AND JB1.EFFSEQ = ( SELECT MAX(J3.EFFSEQ) FROM PS_JOB J3 WHERE JB1.EMPLID = J3.EMPLID AND JB1.EMPL_RCD = J3.EMPL_RCD AND JB1.EFFDT = J3.EFFDT ) ) JB2 ON JB2.EMPLID = PD.EMPLID WHERE EXISTS ( SELECT 'X' FROM PS_PC_RATE_EMPL EMPL WHERE EMPL.EMPLID = PD.EMPLID)
|