select 'Hochschulen in NRW', 0::char(10) as hs_nr, null::char(10) as parent, 0::smallint as ebene from xdummy
union select bezeichnung, laufnummer::char(10), '0'::char(10) as parent, 1 as ebene from sxc_hsk_hochschultypen
--Element kann sich nicht selbst als parent haben!!
--die Einzelhochschulen
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
hs_nr is not null and hsk_laufnummer not in (select hsk_laufnummer from sxc_hochschulen_standorte where hauptsitz='1')
and hsk_bundesland='Nordrhein-Westfalen'
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
hs_nr is not null and hsk_laufnummer in (select hsk_laufnummer from sxc_hochschulen_standorte where hauptsitz='1')
and hsk_bundesland='Nordrhein-Westfalen'
--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
and hs_nr_hauptsitz in (select hs_nr from sxc_hochschulen where hsk_bundesland='Nordrhein-Westfalen')
create view sxc_hochschulen_nrw_liste (druck, apnr, parent, ebene) as
select 'Hochschulen', 0::char(10) as hs_nr, null::char(10) as parent, 0::smallint as ebene from xdummy
union
select name, hs_nr::char(10), '0'::char(10) as parent, 1::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')
and hsk_bundesland='Nordrhein-Westfalen'
union
select name, 'ST_'||hs_nr::char(10), '0'::char(10) as parent, 1::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')
and hsk_bundesland='Nordrhein-Westfalen'
--und die Standorte
union select trim(name)|| ' Standort '||standort_ort, hs_nr::char(10), 'ST_'||hs_nr_hauptsitz as parent, 1::smallint as ebene from sxc_hochschulen_standorte
where hs_nr_hauptsitz is not null and hs_nr is not null
and hs_nr_hauptsitz in (select hs_nr from sxc_hochschulen where hsk_bundesland='Nordrhein-Westfalen')