
INSERT INTO wb_gl VALUES
(1, 'Matzner Hügel'),
(2, 'Wolkersdorfer Hochleiten'),
(3, 'Falkensteiner Hügelland');

INSERT INTO branch VALUES
('M', 'Matzen');

-- 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)
INSERT INTO wb_gem
SELECT gkz, 'WLNS'
FROM AT_gem
WHERE gkz / 100 IN (107);

-- Leithaberg
-- Bezirke Eisenstadt Umgebung (103), Eisenstadt (101), Rust (102)
INSERT INTO wb_gem
SELECT gkz, 'WLLB'
FROM AT_gem
WHERE gkz / 100 IN (101, 102, 103);

-- 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);

INSERT INTO wb_kg
SELECT k.kgnr, 1
FROM wb_gem wg
    LEFT JOIN AT_gem g ON g.gkz = wg.gkz
    LEFT JOIN AT_kg k ON k.gkz = g.gkz
WHERE origin = 'WLWV' AND g.gkz / 100 IN (308, 316) AND k.name IN
    ('Angern', 'Großschweinbarth', 'Mannersdorf', 'Prottes', 'Stillfried', 'Grub an der March', 'Auersthal', 'Dörfles',
     'Ebenthal', 'Hohenruppersdorf', 'Kleinharras', 'Kollnbrunn', 'Matzen', 'Ollersdorf', 'Pirawarth', 'Raggendorf',
     'Reyersdorf', 'Schönkirchen', 'Spannberg', 'Stripfing', 'Tallesbrunn', 'Götzendorf', 'Velm', 'Waidendorf',
     'Dürnkrut', 'Baumgarten an der March', 'Gänserndorf', 'Weikendorf');

INSERT INTO wb_kg
SELECT k.kgnr, 2
FROM wb_gem wg
    LEFT JOIN AT_gem g ON g.gkz = wg.gkz
    LEFT JOIN AT_kg k ON k.gkz = g.gkz
WHERE origin = 'WLWV' AND g.gkz / 100 IN (308, 316) AND k.name IN ('Bockfließ', 'Großengersdorf');

INSERT INTO wb_kg
SELECT k.kgnr, 3
FROM wb_gem wg
    LEFT JOIN AT_gem g ON g.gkz = wg.gkz
    LEFT JOIN AT_kg k ON k.gkz = g.gkz
WHERE origin = 'WLWV' AND g.gkz / 100 IN (308, 316) AND
      k.name IN ('Erdpreß', 'Martinsdorf', 'Niedersulz', 'Großinzersdorf', 'Palterndorf');
