Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.96 KB | None | 0 0
  1. WITH cteContractFipsMatches (contract_h_name, plan_name, segment, fipsRowToMatch) AS (  
  2.  SELECT
  3.   t1.contract_h_name
  4.   ,t1.plan_name
  5.   ,t1.segment
  6.   ,MIN(f1.rownum) AS fipsRowToMatch
  7.  FROM  
  8.   mds_schema.mds_wc_tmp_moc_plan_county t1
  9.   INNER JOIN
  10.   mds_schema.mds_vFips_wc f1 ON t1.fips = f1.fips
  11.  GROUP BY contract_h_name, plan_name, segment
  12. )  
  13.  
  14. SELECT DISTINCT  
  15.  z.[zip code],f1.fips, c1.county_name -- , cte1.contract_h_name, cte1.plan_name, cte1.segment, t1.planDetailsUrl
  16. FROM  
  17.  cteContractFipsMatches cte1
  18. INNER JOIN  
  19.  mds_schema.mds_vFips_wc f1 ON cte1.fipsRowToMatch = f1.rownum
  20. INNER JOIN
  21.  mds_schema.mds_county c1 ON f1.fips = c1.fips
  22. INNER JOIN
  23.  mds_schema.mds_wc_tmp_moc_plan_county t1 ON cte1.contract_h_name = t1.contract_h_name
  24.  AND
  25.  cte1.plan_name = t1.plan_name
  26.  AND
  27.  cte1.segment = t1.segment
  28.  AND
  29.  f1.fips = t1.fips
  30. INNER JOIN
  31.  mds_schema.mds_zip_preferred z ON (z.fips=f1.fips)
  32. INNER JOIN
  33.  dbo.alex_fips a ON z.fips = f1.fips
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement