SELECT A.ESTABID ,A.EFFDT AS start_date , B.EFFDT AS end_date , A.FPAS_CD_BRA , A.THIRD_PARTY_CD_BRA ,C.ENT_CODE_BRA ,CASE WHEN C.ENT_CODE_BRA IS NOT NULL THEN 'Y' END FROM %Table(ESTAB_TBL_BRA) B , %Table(ESTAB_TBL_BRA) A LEFT OUTER JOIN %Table(FPAS_JUD_C_BRA) C ON A.ESTABID = C.ESTABID AND A.EFFDT = C.EFFDT AND A.COUNTY_CD_BRA = C.COUNTY_CD_BRA 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 ,C.ENT_CODE_BRA ,CASE WHEN C.ENT_CODE_BRA IS NOT NULL THEN 'Y' END FROM %Table(ESTAB_TBL_BRA) B , %Table(ESTAB_TBL_BRA) A LEFT OUTER JOIN %Table(FPAS_JUD_C_BRA) C ON A.ESTABID = C.ESTABID AND A.EFFDT = C.EFFDT AND A.COUNTY_CD_BRA = C.COUNTY_CD_BRA WHERE A.ESTABID = B.ESTABID AND A.EFFDT = ( SELECT MAX (A1.EFFDT) FROM %Table(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
|