SELECT CAST (ga.id AS NUMBER (10)) id,
          ga.stofgruppe,
          DBMS_LOB.SUBSTR (ga.stoffer_over_det, 4000, 1) stoffer_over_det,
          ga.stofgruppe_tekst,
          ga.anlaegs_navn,
          ga.virksomhedstype_tekst,
          b.borid,
          bb.dgunr dgu_nr,
          ga.indtagsid,
          ga.indtag_nr,
          b.aktiv_indvinding_jn,
          CAST (ga.indtag_top_dybde AS NUMBER (7, 2)) indtag_top_dybde,
          al.lang_tekst boringsanvendelse,
          TO_CHAR (ga.dato_seneste_analyse, 'YYYY-MM-DD')
             dato_seneste_analyse,
          CAST (ga.analyser_10_aar AS NUMBER (7)) analyser_10_aar,
          CAST (ga.status_indtag AS NUMBER (3)) status_indtag,
          ga.status_indtag_forklaret,
          CAST (ga.stofnr AS NUMBER (4)) stofnr,
          ga.stof_tekst,
          CAST (ga.maengde AS NUMBER (13, 3)) maengde,
          TO_CHAR (ga.dato, 'YYYY-MM-DD') dato,
          ga.overanlaegs_navn,
          ga.anlaeg_id,
          ga.virksomhedstype_kode,
          ga.kommune_nr,
          ga.kommune_navn,
          ml.kode mc_kode,
          ml.lang_tekst mc_navn,
          rl.kode region_kode,
          rl.lang_tekst region_navn,
          fl.lang_tekst boringsformaal,
          ga.indtag_anvendelse_tekst,
          bb.zdvr90 terraen_kote,
          bb.boringsdybde,
          bb.xutm32euref89,
          bb.yutm32euref89,
          CAST (ga.indtag_top_dybde_forklaret AS NUMBER (1))
             indtag_top_dybde_forklaret,
          CAST (ga.indtag_bund_dybde AS NUMBER (7, 2)) indtag_bund_dybde,
          CAST (ga.indtag_bund_dybde_forklaret AS NUMBER (1))
             indtag_bund_dybde_forklaret,
          CAST (ga.graensevaerdi_max AS NUMBER (13, 3)) graensevaerdi_max,
          ga.indtags_bjergart,
          ga.akvitard_over_indtag_m,
          ga.magasin_over_indtag_m,
          ga.ukendt_over_indtag_m,
          ga.boringskvalitet,
          b.hoved_vandopland,
          vt.vandtype,
          b.sloejfet_jn,
          TO_CHAR (b.udtraeksdato, 'YYYY-MM-DD') udtraeksdato,
          bs.punkt_utm32 geom,
          NVL (ga.rgb, '255 255 255') rgb,
          ga.symbol,
          ga.symbol_size,
          ga.symbol_txt_size,
          ga.cache_date
     FROM mcportal.mc_boring b
          INNER JOIN bor$boring$v bb
             ON bb.borid = b.borid                          -- fortrolig='nej'
          INNER JOIN bor$boring_spatial bs
             ON bs.borid = b.borid
          LEFT OUTER JOIN gen$miljoecenter_liste ml
             ON ml.kode = bb.miljoecenter
          LEFT OUTER JOIN gen$region_liste rl
             ON rl.kode = bb.region
          LEFT OUTER JOIN bor$formaal_liste fl
             ON fl.kode = bb.formaal
          LEFT OUTER JOIN bor$anvend_liste al
             ON al.kode = bb.anvendelse
          INNER JOIN mcportal.mc_grp_analyse ga
             ON b.borid = ga.borid
          LEFT OUTER JOIN (  SELECT proeveid, MAX (vandtype) vandtype
                               FROM mcportal.mc_vandtype vt
                           GROUP BY proeveid) vt
             ON vt.proeveid = ga.proeveid_seneste_stoerste;