SELECT A.ESTABID , A.effdt AS start_date , B.effdt AS end_date , A.FPAS_CD_BRA , A.THIRD_PARTY_CD_BRA FROM %Table(ESTAB_TBL_BRA) A , %Table(ESTAB_TBL_BRA) B WHERE B.EFFDT = ( SELECT MIN (B1.EFFDT) FROM %Table(ESTAB_TBL_BRA) B1 WHERE B1.EFFDT > A.EFFDT AND A.ESTABID=B1.ESTABID) UNION SELECT A.ESTABID , A.effdt AS start_date , %DateIn ('2999,12,31') AS end_date , A.FPAS_CD_BRA , A.THIRD_PARTY_CD_BRA FROM %Table(ESTAB_TBL_BRA) A , %Table(ESTAB_TBL_BRA) B WHERE A.ESTABID = B.ESTABID AND A.EFFDT = ( SELECT MAX (A1.EFFDT) FROM PS_ESTAB_TBL_BRA A1 WHERE A.ESTABID = A1.ESTABID) AND A.FPAS_CD_BRA = B.FPAS_CD_BRA AND A.THIRD_PARTY_CD_BRA = B.THIRD_PARTY_CD_BRA
|