SELECT DISTINCT JOB.EMPLID , JOB.EMPL_RCD , JOB.EFFDT , INAIL.INAIL_CODE , JOB.COMPANY , JOB.ESTABID , I.INAIL_POS_CD_ITA FROM PS_JOB JOB , PS_INAIL_COMP_ITA INAIL , PS_INAIL_TBL_ITA I WHERE JOB.COMPANY = INAIL.COMPANY AND (JOB.ESTABID = INAIL.ESTABID OR INAIL.ESTABID = ' ') AND JOB.EFFDT = ( SELECT MAX(JOB2.EFFDT) FROM PS_JOB JOB2 WHERE JOB.EMPLID=JOB2.EMPLID AND JOB2.EFFDT<=JOB.EFFDT) AND JOB.EFFSEQ = ( SELECT MAX(JOB2.EFFSEQ) FROM PS_JOB JOB2 WHERE JOB.EMPLID=JOB2.EMPLID AND JOB2.EFFDT<=JOB.EFFDT) AND INAIL.INAIL_CODE = I.INAIL_CODE AND INAIL.EFFDT = ( SELECT MAX(INAIL2.EFFDT) FROM PS_INAIL_COMP_ITA INAIL2 WHERE INAIL2.INAIL_CODE = INAIL.INAIL_CODE AND JOB.COMPANY = INAIL2.COMPANY AND (INAIL.ESTABID = INAIL2.ESTABID OR INAIL2.ESTABID = ' ') AND INAIL2.EFF_STATUS = 'A')
|