Guest User

Untitled

a guest
Nov 17th, 2018
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. INSERT INTO GEO_AREA ( Geo_Area_Nm, Geo_Area_Abrv, Geo_Area_Full_Qualfd_Nm, Geo_Area_Full_Qualfd_Abrv,
  2. Geo_Area_Typ_CK, Geo_Area_Prim_ID, Last_Modfd_By_ID, Crtd_By_ID
  3. )
  4. SELECT
  5. Concat("Precinct ", S.PrecinctNumber) AS Geo_Area_Nm, -- The plain Precinct identifier, preceded by the word "Precinct",
  6. -- without any county or state information added.
  7. S.PrecinctNumber AS Geo_Area_Abrv, -- The plain Precinct identifier without any county or state information added.
  8. Concat(S.Jurisname, ", ", STATE.Geo_Area_Nm," - Precinct: ",
  9. S.PrecinctNumber) AS Geo_Area_Full_Qualfd_Nm, -- [Elector Jurisdiction name, State Name:] Precinct: [Precinct ID]
  10. Concat(S.Jurisname, ", ", STATE.Geo_Area_Abrv," - Prcnct: ",
  11. S.PrecinctNumber) AS Geo_Area_Full_Qualfd_Nm, -- [Elector Jurisdiction name, State Name:] Precinct: [Precinct ID]
  12. @Prcnct_CK AS Geo_Area_Typ_CK, -- => Precinct
  13. Concat("US-", S.State, "-",S.Juriscode, "-Prcnct:", S.PrecinctNumber) AS Geo_Area_Prim_ID,
  14. -- Example: US-WY-5602100000-Prcnct:3 08
  15. Max(Concat("DTVF-", S.SourceID)) As Last_Modfd_By_ID,
  16. Max(Concat("DTVF-", S.SourceID)) As Crtd_By_ID
  17. FROM VW_STG_DATA_TRUST_VOTR_INSERT S
  18. LEFT JOIN GEO_AREA STATE -- STATE is the source of the State name and abbreviation that was loaded in Initial LOAD
  19. ON Concat('US-',S.State) = STATE.Geo_Area_Prim_ID
  20. LEFT JOIN GEO_AREA EXIST_GA -- EXIST_GA is the set of records in GEO_AREA before this insert
  21. ON Concat("US-", S.State, "-",S.Juriscode, "-Prcnct:", S.PrecinctNumber) = EXIST_GA.Geo_Area_Prim_ID
  22. WHERE STATE.Geo_Area_Typ_CK = @State_CK -- => Connection for US State level info
  23. -- AND Concat(S.JurisName, ", ", STATE.Geo_Area_Nm) = 'Abbotsford City, Wisconsin'
  24. AND EXIST_GA.Geo_Area_Prim_ID IS NULL
  25. GROUP BY 1,2,3,4,5,6
  26. ;
  27.  
  28. SELECT * FROM GEO_AREA WHERE Geo_Area_Typ_CK in (252, 255) order by 6 desc, 4;
Add Comment
Please, Sign In to add comment