
----------------------------------------------------------------
-- Weinland
----------------------------------------------------------------

-- Wien
-- Gemeinde Wien
INSERT INTO wb_gem VALUES
(90001, 'WIEN');

-- Weinviertel
-- Bezirke Mistelbach (316), Gänserndorf (308), Korneuburg (312), Hollabrunn (310), Horn (311)
INSERT INTO wb_gem
SELECT gkz, 'WLWV'
FROM AT_gem
WHERE gkz / 100 IN (308, 310, 311, 312, 316);

-- Carnuntum
-- Bezirk Bruck/Leitha (307)
INSERT INTO wb_gem
SELECT gkz, 'WLCA'
FROM AT_gem
WHERE gkz / 100 IN (307);

-- Thermenregion
-- Bezirke Mödling (317), Baden (306), Wr. Neustadt (323), Wr. Neustadt (304), Neunkirchen (318)
INSERT INTO wb_gem
SELECT gkz, 'WLTH'
FROM AT_gem
WHERE gkz / 100 IN (304, 306, 317, 318, 323);

-- Traisental
-- Bezirke St. Pölten Land (319), St. Pölten (302)
INSERT INTO wb_gem
SELECT gkz, 'WLTT'
FROM AT_gem
WHERE gkz / 100 IN (302, 319);

-- Wagram
-- Bezirk Tulln (321)
INSERT INTO wb_gem
SELECT gkz, 'WLWG'
FROM AT_gem
WHERE gkz / 100 IN (321);

-- Kamptal
-- Gemeinden Grafenegg (31308), Straß im Straßertale (31346), Schönberg am Kamp (31355), Langenlois (31322),
--           Hadersdorf-Kammern (31315), Lengenfeld (31323)
INSERT INTO wb_gem
SELECT gkz, 'WLKA'
FROM AT_gem
WHERE gkz IN (31308, 31346, 31355, 31322, 31315, 31323);

-- Kremstal
-- Gemeinden Krems an der Donau (30101), Stratzing (31347), Droß (31356), Senftenberg (31343), Paudorf (31333),
--           Furth bei Göttweig (31309)
INSERT INTO wb_gem
SELECT gkz, 'WLKT'
FROM AT_gem
WHERE gkz IN (30101, 31347, 31356, 31343, 31333, 31309);

-- Wachau
-- Gemeinden Mautern an der Donau (31327), Bergern im Dunkelsteinerwald (31303), Dürnstein (31304),
--           Rossatz-Arnsdorf (31338), Aggsbach (31301), Spitz (31344), Mühldorf (31330),
--           Weißenkirchen in der Wachau (31351)
INSERT INTO wb_gem
SELECT gkz, 'WLWA'
FROM AT_gem
WHERE gkz IN (31327, 31303, 31304, 31338, 31301, 31344, 31330, 31351);

-- Neusiedlersee
-- Bezirk Neusiedl am See (107)
-- ohne Gemeinden Jois (10710), Winden am See (10723)
INSERT INTO wb_gem
SELECT gkz, 'WLNS'
FROM AT_gem
WHERE gkz / 100 IN (107) AND gkz NOT IN (10710, 10723);

-- Leithaberg
-- Bezirke Eisenstadt Umgebung (103), Eisenstadt (101), Rust (102)
-- Gemeinden Jois (10710), Winden am See (10723)
INSERT INTO wb_gem
SELECT gkz, 'WLLB'
FROM AT_gem
WHERE gkz / 100 IN (101, 102, 103) OR gkz IN (10710, 10723);

-- Rosalia
-- Bezirk Mattersburg (106)
INSERT INTO wb_gem
SELECT gkz, 'WLRO'
FROM AT_gem
WHERE gkz / 100 IN (106);

-- Mittelburgenland
-- Bezirk Oberpullendorf (106)
INSERT INTO wb_gem
SELECT gkz, 'WLMB'
FROM AT_gem
WHERE gkz / 100 IN (108);

-- Eisenberg
-- Bezirke Oberwart (109), Güssing (104), Jennersdorf (105)
INSERT INTO wb_gem
SELECT gkz, 'WLEB'
FROM AT_gem
WHERE gkz / 100 IN (104, 105, 109);

-- Niederösterreich
INSERT INTO wb_gem
SELECT a.gkz, 'WLNO'
FROM AT_gem a
    LEFT JOIN wb_gem w ON w.gkz = a.gkz
WHERE a.gkz / 10000 = 3 AND w.hkid IS NULL;


----------------------------------------------------------------
-- Steirerland
----------------------------------------------------------------

-- Vulkanland Steiermark
-- Bezirke Hartberg-Fürstenfeld (622), Südoststeiermark (623), Weiz (617)
-- Teile der Bezirke Leibnitz (610), Graz-Umgebung (606)
INSERT INTO wb_gem
SELECT gkz, 'SLVL'
FROM AT_gem
WHERE gkz / 100 IN (617, 622, 623);

-- Südsteiermark
-- Bezirk Leibnitz (610)
-- ohne Gemeinden Empersdorf (61007), Heiligenkreuz am Waasen (61052), Allerheiligen bei Wildon (61001),
--                Sankt Georgen a.d.Stiefing (61055), Ragnitz (61027), Schwarzautal (61057), Gabersdorf (61008),
--                Sankt Veit in der Südsteiermark (61057)
INSERT INTO wb_gem
SELECT gkz, 'SLSS'
FROM AT_gem
WHERE gkz / 100 = 610;
UPDATE wb_gem
SET hkid = 'SLVL'
WHERE gkz IN (61007, 61052, 61001, 61055, 61027, 61057, 61008, 61057);

-- Weststeiermark
-- Bezirke Deutschlandsberg (603), Voitsberg (616)
-- Geminden Graz (60101), Frohnleiten (60663), Übelbach (60651), Deutschfeistritz (60659), Gratwein-Straßengel (60664),
--          Stiwoll (60647), Sankt Oswald bei Plankenwarth (60641), Sankt Bartholomä (60639), Thal (60648),
--          Hitzendorf (60665), Seiersberg-Pirka (60669), Haselsdorf-Tobelbad (60618), Lieboch (60629),
--          Feldkirchen bei Graz (60608), Premstätten (60670), Kalsdorf bei Graz (60624), Dobl-Zwaring (60660),
--          Wundschuh (60656), Werndorf (60655)
INSERT INTO wb_gem
SELECT gkz, 'SLWS'
FROM AT_gem
WHERE gkz / 100 IN (603, 616) OR gkz IN (60101, 60663, 60651, 60659, 60664, 60647, 60641, 60639, 60665, 60669, 60618,
                                         60629, 60608, 60670, 60624, 60660, 60656, 60655);
INSERT INTO wb_gem
SELECT g.gkz, 'SLVL'
FROM AT_gem g
    LEFT JOIN wb_gem w ON w.gkz = g.gkz
WHERE g.gkz / 100 = 606 AND w.hkid IS NULL;

-- Steiermark
INSERT INTO wb_gem
SELECT g.gkz, 'SLST'
FROM AT_gem g
    LEFT JOIN wb_gem w ON w.gkz = g.gkz
WHERE g.gkz / 10000 = 6 AND w.hkid IS NULL;


----------------------------------------------------------------
-- Bergland
----------------------------------------------------------------

-- Oberösterreich
INSERT INTO wb_gem
SELECT gkz, 'BLOO'
FROM AT_gem
WHERE gkz / 10000 = 4;

-- Kärnten
INSERT INTO wb_gem
SELECT gkz, 'BLKA'
FROM AT_gem
WHERE gkz / 10000 = 2;

-- Salzburg
INSERT INTO wb_gem
SELECT gkz, 'BLSB'
FROM AT_gem
WHERE gkz / 10000 = 5;

-- Tirol
INSERT INTO wb_gem
SELECT gkz, 'BLTI'
FROM AT_gem
WHERE gkz / 10000 = 7;

-- Vorarlberg
INSERT INTO wb_gem
SELECT gkz, 'BLVO'
FROM AT_gem
WHERE gkz / 10000 = 8;
