Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INSERT INTO GEO_AREA ( Geo_Area_Nm, Geo_Area_Abrv, Geo_Area_Full_Qualfd_Nm, Geo_Area_Full_Qualfd_Abrv,
- Geo_Area_Typ_CK, Geo_Area_Prim_ID, Last_Modfd_By_ID, Crtd_By_ID
- )
- SELECT
- Concat("Precinct ", S.PrecinctNumber) AS Geo_Area_Nm, -- The plain Precinct identifier, preceded by the word "Precinct",
- -- without any county or state information added.
- S.PrecinctNumber AS Geo_Area_Abrv, -- The plain Precinct identifier without any county or state information added.
- Concat(S.Jurisname, ", ", STATE.Geo_Area_Nm," - Precinct: ",
- S.PrecinctNumber) AS Geo_Area_Full_Qualfd_Nm, -- [Elector Jurisdiction name, State Name:] Precinct: [Precinct ID]
- Concat(S.Jurisname, ", ", STATE.Geo_Area_Abrv," - Prcnct: ",
- S.PrecinctNumber) AS Geo_Area_Full_Qualfd_Nm, -- [Elector Jurisdiction name, State Name:] Precinct: [Precinct ID]
- @Prcnct_CK AS Geo_Area_Typ_CK, -- => Precinct
- Concat("US-", S.State, "-",S.Juriscode, "-Prcnct:", S.PrecinctNumber) AS Geo_Area_Prim_ID,
- -- Example: US-WY-5602100000-Prcnct:3 08
- Max(Concat("DTVF-", S.SourceID)) As Last_Modfd_By_ID,
- Max(Concat("DTVF-", S.SourceID)) As Crtd_By_ID
- FROM VW_STG_DATA_TRUST_VOTR_INSERT S
- LEFT JOIN GEO_AREA STATE -- STATE is the source of the State name and abbreviation that was loaded in Initial LOAD
- ON Concat('US-',S.State) = STATE.Geo_Area_Prim_ID
- LEFT JOIN GEO_AREA EXIST_GA -- EXIST_GA is the set of records in GEO_AREA before this insert
- ON Concat("US-", S.State, "-",S.Juriscode, "-Prcnct:", S.PrecinctNumber) = EXIST_GA.Geo_Area_Prim_ID
- WHERE STATE.Geo_Area_Typ_CK = @State_CK -- => Connection for US State level info
- -- AND Concat(S.JurisName, ", ", STATE.Geo_Area_Nm) = 'Abbotsford City, Wisconsin'
- AND EXIST_GA.Geo_Area_Prim_ID IS NULL
- GROUP BY 1,2,3,4,5,6
- ;
- 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