Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH cteContractFipsMatches (contract_h_name, plan_name, segment, fipsRowToMatch) AS (
- SELECT
- t1.contract_h_name
- ,t1.plan_name
- ,t1.segment
- ,MIN(f1.rownum) AS fipsRowToMatch
- FROM
- mds_schema.mds_wc_tmp_moc_plan_county t1
- INNER JOIN
- mds_schema.mds_vFips_wc f1 ON t1.fips = f1.fips
- GROUP BY contract_h_name, plan_name, segment
- )
- SELECT DISTINCT
- z.[zip code],f1.fips, c1.county_name -- , cte1.contract_h_name, cte1.plan_name, cte1.segment, t1.planDetailsUrl
- FROM
- cteContractFipsMatches cte1
- INNER JOIN
- mds_schema.mds_vFips_wc f1 ON cte1.fipsRowToMatch = f1.rownum
- INNER JOIN
- mds_schema.mds_county c1 ON f1.fips = c1.fips
- INNER JOIN
- mds_schema.mds_wc_tmp_moc_plan_county t1 ON cte1.contract_h_name = t1.contract_h_name
- AND
- cte1.plan_name = t1.plan_name
- AND
- cte1.segment = t1.segment
- AND
- f1.fips = t1.fips
- INNER JOIN
- mds_schema.mds_zip_preferred z ON (z.fips=f1.fips)
- INNER JOIN
- dbo.alex_fips a ON z.fips = f1.fips
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement