<sqldbsystem=""><![CDATA[SELECT 'Hochschulen'::varchar AS druck,
<sqldbsystem=""><![CDATA[
0 AS apnr,
select 'Hochschulen', 0::char(10) as hs_nr, null::char(10) as parent, 0::smallint as ebene from xdummy
NULL::integer AS parent,
union select bezeichnung, laufnummer::char(10), '0'::char(10) as parent, 1 as ebene from sxc_hsk_hochschultypen
0::smallint AS ebene
--Element kann sich nicht selbst als parent haben!!
FROM xdummy
--die Einzelhochschulen
UNION
union select name, hs_nr::char(10), (select laufnummer from sxc_hsk_hochschultypen H where H.bezeichnung=sxc_hochschulen.hsk_art)::char(10) as parent, 2::smallint as ebene from sxc_hochschulen where
SELECT sxc_hsk_hochschultypen.bezeichnung AS druck,
hs_nr is not null and hsk_laufnummer not in (select hsk_laufnummer from sxc_hochschulen_standorte where hauptsitz='1')
sxc_hsk_hochschultypen.laufnummer AS apnr,
union select name, 'ST_'||hs_nr::char(10), (select laufnummer from sxc_hsk_hochschultypen H where H.bezeichnung=sxc_hochschulen.hsk_art)::char(10) as parent, 2::smallint as ebene from sxc_hochschulen where
0 AS parent,
hs_nr is not null and hsk_laufnummer in (select hsk_laufnummer from sxc_hochschulen_standorte where hauptsitz='1')
1 AS ebene
--und die Standorte
FROM sxc_hsk_hochschultypen
union select trim(name)|| ' Standort '||standort_ort, hs_nr::char(10), 'ST_'||hs_nr_hauptsitz as parent, 3::smallint as ebene from sxc_hochschulen_standorte
UNION
where hs_nr_hauptsitz is not null and hs_nr is not null;
SELECT 'nicht zugeordnet'::varchar AS druck,
99 AS apnr,
0 AS parent,
1 AS ebene
FROM xdummy
UNION
SELECT sxc_hochschulen.name AS druck,
sxc_hochschulen.hs_nr AS apnr,
(( SELECT h.laufnummer
FROM sxc_hsk_hochschultypen h
WHERE h.bezeichnung = sxc_hochschulen.hrk_art))::integer AS parent,
2::smallint AS ebene
FROM sxc_hochschulen
WHERE sxc_hochschulen.hrk_laufnummer IS NOT NULL AND sxc_hochschulen.hs_nr_hauptsitz IS NULL
UNION
SELECT sxc_hochschulen.name AS druck,
sxc_hochschulen.hs_nr * 100 AS apnr,
(( SELECT h.laufnummer
FROM sxc_hsk_hochschultypen h
WHERE h.bezeichnung = sxc_hochschulen.hrk_art))::integer AS parent,
2::smallint AS ebene
FROM sxc_hochschulen
WHERE sxc_hochschulen.hrk_laufnummer IS NOT NULL AND sxc_hochschulen.hs_nr_hauptsitz = 1
UNION
SELECT sxc_hochschulen.name AS druck,
sxc_hochschulen.hs_nr AS apnr,
99 AS parent,
2::smallint AS ebene
FROM sxc_hochschulen
WHERE sxc_hochschulen.hrk_laufnummer IS NULL AND sxc_hochschulen.hrk_hauptsitz IS NULL
UNION
SELECT sxc_hochschulen.name AS druck,
sxc_hochschulen.hs_nr AS apnr,
sxc_hochschulen.hs_nr_hauptsitz * 100 AS parent,
3::smallint AS ebene
FROM sxc_hochschulen
WHERE sxc_hochschulen.hrk_laufnummer IS NULL AND sxc_hochschulen.hs_nr_hauptsitz IS NOT NULL
UNION
SELECT btrim(s.name::text) || ' (Hauptsitz)'::text AS druck,
s.hs_nr AS apnr,
s.hs_nr * 100 AS parent,
3::smallint AS ebene
FROM sxc_hochschulen s
WHERE s.hrk_laufnummer IS NOT NULL AND s.hs_nr_hauptsitz = 1 AND (EXISTS ( SELECT s1.hrk_hauptsitz
select 'Hochschulen', 0::char(10) as hs_nr, null::char(10) as parent, 0::smallint as ebene from xdummy
union select hsk_bundesland, substring(hsk_bundesland, 1,10), '0'::char(10) as parent, 1 as ebene from sxc_hochschulen
--Element kann sich nicht selbst als parent haben!!
--die Einzelhochschulen
union select name, hs_nr::char(10), substring(hsk_bundesland, 1,10) as parent, 2::smallint as ebene from sxc_hochschulen where
hs_nr is not null and hsk_laufnummer not in (select hsk_laufnummer from sxc_hochschulen_standorte where hauptsitz='1')
union select name, 'ST_'||hs_nr::char(10), substring(hsk_bundesland, 1,10) as parent, 2::smallint as ebene from sxc_hochschulen where
hs_nr is not null and hsk_laufnummer in (select hsk_laufnummer from sxc_hochschulen_standorte where hauptsitz='1')
--und die Standorte
union select trim(name)|| ' Standort '||standort_ort, hs_nr::char(10), 'ST_'||hs_nr_hauptsitz as parent, 3::smallint as ebene from sxc_hochschulen_standorte
where hs_nr_hauptsitz is not null and hs_nr is not null;