SELECT A.ESTABID , A.START_DATE AS EFFDT , A.FPAS_CD_BRA , A.THIRD_PARTY_CD_BRA , B.ENT_CODE_BRA , B.ENT_PCT_BRA FROM %Table(E_FPAS_R_BRA_VW) A , %Table(FPAS_ENT_BRA) B , %Table(FPAS_TBL_BRA) C WHERE A.FPAS_CD_BRA = B.FPAS_CD_BRA AND A.THIRD_PARTY_CD_BRA = B.THIRD_PARTY_CD_BRA AND B.FPAS_CD_BRA = C.FPAS_CD_BRA AND B.EFFDT = C.EFFDT AND C.EFF_STATUS = 'A' AND B.EFFDT = ( SELECT MAX (B1.EFFDT) FROM %Table(FPAS_ENT_BRA) B1 WHERE A.FPAS_CD_BRA = B1.FPAS_CD_BRA AND A.THIRD_PARTY_CD_BRA = B1.THIRD_PARTY_CD_BRA AND B1.EFFDT <= A.START_DATE) UNION ALL SELECT A.ESTABID , B.EFFDT AS EFFDT , A.FPAS_CD_BRA , A.THIRD_PARTY_CD_BRA , B.ENT_CODE_BRA , B.ENT_PCT_BRA FROM %Table(E_FPAS_R_BRA_VW) A , %Table(FPAS_ENT_BRA) B , %Table(FPAS_TBL_BRA) C WHERE B.FPAS_CD_BRA = A.FPAS_CD_BRA AND B.THIRD_PARTY_CD_BRA = A.THIRD_PARTY_CD_BRA AND B.FPAS_CD_BRA = C.FPAS_CD_BRA AND B.EFFDT = C.EFFDT AND C.EFF_STATUS = 'A' AND B.EFFDT > A.START_DATE AND B.EFFDT < A.END_DATE
|