SELECT B.OPRID , A.EMPLID , D.DEPTID , C.SUPERVISOR_ID , C.PHONE , C.REPORTS_TO , B.EMAILID FROM PS_PERSONAL_DATA A , PSOPRDEFN B , PS_EMPLOYMENT C , PS_JOB D WHERE D.EMPLID = C.EMPLID AND A.EMPLID = C.EMPLID AND D.EFFDT = ( SELECT MAX(D1.EFFDT) FROM PS_JOB D1 WHERE D1.EMPLID = D.EMPLID AND D1.EFFDT <= %CurrentDateIn) AND D.EFFSEQ = ( SELECT MAX(D2.EFFSEQ) FROM PS_JOB D2 WHERE D2.EMPLID = D.EMPLID AND D2.EFFDT = D.EFFDT) AND A.EMPLID = B.EMPLID AND D.EMPL_STATUS = 'A' UNION SELECT B.OPRID , ' ' , ' ' , ' ' , ' ' , ' ' , B.EMAILID FROM PSOPRDEFN B WHERE NOT EXISTS ( SELECT 'X' FROM PS_JOB D WHERE B.EMPLID = D.EMPLID) OR EXISTS( SELECT 'X' FROM PS_JOB D WHERE B.EMPLID = D.EMPLID AND D.EFFDT = ( SELECT MAX(D1.EFFDT) FROM PS_JOB D1 WHERE D1.EMPLID = D.EMPLID AND D1.EFFDT <= %CurrentDateIn) AND D.EFFSEQ = ( SELECT MAX(D2.EFFSEQ) FROM PS_JOB D2 WHERE D2.EMPLID = D.EMPLID AND D2.EFFDT = D.EFFDT) AND D.EMPL_STATUS <> 'A')
|