
DROP VIEW LD0VAA0Internship
;

CREATE VIEW LD0VAA0Internship
AS 
SELECT
  U60.*,
  Q01_1.KLARTEXT AS PRAKTIKTYP_T,
  Q01_2.KLARTEXT AS PRAKTIKTID_T,
  Q01_3.KLARTEXT AS SOKORD1_T,
  Q01_4.KLARTEXT AS SOKORD2_T,
  Q01_5.KLARTEXT AS INRIKTNING_T,
  Q01_6.KLARTEXT AS DELTAGARERS_T,
  Q01_7.KLARTEXT AS DELTAGARERS2_T,
  Q01_8.KLARTEXT AS DELTAGARERS3_T,
  Q01_9.KLARTEXT AS INSKRIVNFORF_T,
  Q01_10.KLARTEXT AS DELTAGBEVIS_T,
  Q01_11.KLARTEXT AS STUDIEBESOK_T,
  Q01_12.KLARTEXT AS GODKANDFACK_T,
  Q01_13.KLARTEXT AS GODKANDAF_T,
  U99_1.EXTTEXT AS PRAKTIKUPPG_T1,
  U99_2.EXTTEXT AS PRAKTIKUPPG_T2
FROM LD0V0U60 AS U60
  LEFT OUTER JOIN LD0V0Q01 AS Q01_1 ON Q01_1.KODTYP = 'LNPRAKTYP' AND U60.PRAKTIKTYP = Q01_1.KOD
  LEFT OUTER JOIN LD0V0Q01 AS Q01_2 ON Q01_2.KODTYP = 'LNPRADETID' AND U60.PRAKTIKTID = Q01_2.KOD
  LEFT OUTER JOIN LD0V0Q01 AS Q01_3 ON Q01_3.KODTYP = 'LNSOKORD' AND U60.SOKORD1 = Q01_3.KOD
  LEFT OUTER JOIN LD0V0Q01 AS Q01_4 ON Q01_4.KODTYP = 'LNSOKORD' AND U60.SOKORD2 = Q01_4.KOD
  LEFT OUTER JOIN LD0V0Q01 AS Q01_5 ON Q01_5.KODTYP = 'LNINRIKTN' AND U60.INRIKTNING = Q01_5.KOD
  LEFT OUTER JOIN LD0V0Q01 AS Q01_6 ON Q01_6.KODTYP = 'LNDELTERS' AND U60.DELTAGARERS = Q01_6.KOD
  LEFT OUTER JOIN LD0V0Q01 AS Q01_7 ON Q01_7.KODTYP = 'LNDELTERS' AND U60.DELTAGARERS2 = Q01_7.KOD
  LEFT OUTER JOIN LD0V0Q01 AS Q01_8 ON Q01_8.KODTYP = 'LNDELTERS' AND U60.DELTAGARERS3 = Q01_8.KOD
  LEFT OUTER JOIN LD0V0Q01 AS Q01_9 ON Q01_9.KODTYP = 'LNINSKFORF' AND U60.INSKRIVNFORF = Q01_9.KOD
  LEFT OUTER JOIN LD0V0Q01 AS Q01_10 ON Q01_10.KODTYP = 'LNDELTBEV' AND U60.DELTAGBEVIS = Q01_10.KOD
  LEFT OUTER JOIN LD0V0Q01 AS Q01_11 ON Q01_11.KODTYP = 'LNSTUDBES' AND U60.STUDIEBESOK = Q01_11.KOD
  LEFT OUTER JOIN LD0V0Q01 AS Q01_12 ON Q01_12.KODTYP = 'LNGKFACK' AND U60.GODKANDFACK = Q01_12.KOD
  LEFT OUTER JOIN LD0V0Q01 AS Q01_13 ON Q01_13.KODTYP = 'LNGKABF' AND U60.GODKANDAF = Q01_13.KOD
  LEFT OUTER JOIN LD0V0U99 AS U99_1 ON U99_1.EXTKOD = substring(U60.PRAKTIKUPPG_2012,1,2) AND U99_1.EXTKODTYP = 4 and U99_1.NIVA = 2
  LEFT OUTER JOIN LD0V0U99 AS U99_2 ON U99_2.EXTKOD = U60.PRAKTIKUPPG_2012 AND U99_2.EXTKODTYP = 4 and U99_2.NIVA = 3
;