SELECT A.EMPLID , A.EMPL_RCD , B.EFFDT , B.SETID , B.DEPTID , B.RISKCD , D.AT_SECTION , D.STANDARD_RT , D.AT_CODE_FRA FROM PS_JOB A , PS_DEPT_TBL B , PS_ESTAB_TBL C , PS_RISK_TBL D WHERE A.SETID_DEPT = B.SETID AND A.DEPTID = B.DEPTID AND ( B.EFFDT = ( SELECT MAX(E.EFFDT) FROM PS_DEPT_TBL E WHERE A.SETID_DEPT = E.SETID AND A.DEPTID = E.DEPTID AND E.EFFDT <= A.EFFDT AND E.EFF_STATUS = 'A' ) OR ( B.EFFDT > A.EFFDT AND (B.EFFDT < ( SELECT MIN(F.EFFDT) FROM PS_JOB F WHERE F.EMPLID = A.EMPLID AND F.EMPL_RCD = A.EMPL_RCD AND F.EFFDT > A.EFFDT) OR NOT EXISTS ( SELECT 'X' FROM PS_JOB F WHERE F.EMPLID = A.EMPLID AND F.EMPL_RCD = A.EMPL_RCD AND F.EFFDT > A.EFFDT) ) ) ) AND B.EFF_STATUS = 'A' AND B.ESTABID = C.ESTABID AND B.RISKCD = D.RISKCD AND B.ESTABID = D.ESTABID AND A.ESTABID = C.ESTABID AND C.EFF_STATUS = 'A' AND C.EFFDT = ( SELECT MAX(F.EFFDT) FROM PS_ESTAB_TBL F WHERE B.ESTABID = F.ESTABID AND F.EFFDT <= A.EFFDT AND F.EFF_STATUS = 'A' ) AND D.EFFDT = ( SELECT MAX(F.EFFDT) FROM PS_RISK_TBL F , PS_GP_PYE_SEG_STAT G WHERE B.ESTABID = F.ESTABID AND A.EMPLID = G.EMPLID AND A.EMPL_RCD = G.EMPL_RCD AND G.CALC_ACTION = 'C' AND B.RISKCD = D.RISKCD AND F.EFFDT <= G.SEG_END_DT)
|