CREATE OR ALTER VIEW LD0VAAYLMEnrollment
AS 
SELECT
 U10.*
,A.NAMN as PERSNAMN
,A.KUNDNUMMER AS KUNDNUMMER
,Q1.KLARTEXT AS TYPAVSLUT_T
,Q2.KLARTEXT AS AVSLUTORS_T
,Q3.KLARTEXT AS AVSLUTKOMMUN_T
,Q4.KLARTEXT AS AVSLUTLAND_T
,Q5.KLARTEXT AS INSKRTYP_T
,Q6.KLARTEXT AS UTANARB_T
,Q8.KLARTEXT AS OVRIG1_T
,Q9.KLARTEXT AS OVRIG2_T
,Q10.KLARTEXT AS OVRIG3_T
,J01.NAMN  AS  ORGENH_T
,OMR.NAMN AS OMRADE_NAMN
,U99.NIVA4_EXTEXT AS YRKESKOD_T
FROM LD0VYU10 AS U10
LEFT OUTER JOIN LD0V0A AS A ON A.PNR = U10.PERSONNR
LEFT OUTER JOIN LD0V0Q01 AS Q1 ON Q1.KODTYP = 'LNTYPAVSL' AND U10.TYPAVSLUT = Q1.KOD
LEFT OUTER JOIN LD0V0Q01 AS Q2 ON Q2.KODTYP = 'LNAVSLORS' AND U10.AVSLUTORS = Q2.KOD
LEFT OUTER JOIN LD0V0Q01 AS Q3 ON Q3.KODTYP = 'KOMU' AND U10.AVSLUTKOMMUN = Q3.KOD
LEFT OUTER JOIN LD0V0Q01 AS Q4 ON Q4.KODTYP = 'LAND' AND U10.AVSLUTLAND = Q4.KOD
LEFT OUTER JOIN LD0V0Q01 AS Q5 ON Q5.KODTYP = 'LNINSKTYP' AND U10.INSKRTYP = Q5.KOD
LEFT OUTER JOIN LD0V0Q01 AS Q6 ON Q6.KODTYP = 'LNUTANARB' AND Q6.KOD = U10.UTANARB 
LEFT OUTER JOIN LD0V0Q01 AS Q8 ON Q8.KODTYP = 'LNOVRIG1' AND Q8.KOD = U10.OVRIG1
LEFT OUTER JOIN LD0V0Q01 AS Q9 ON Q9.KODTYP = 'LNOVRIG2' AND Q9.KOD = U10.OVRIG2
LEFT OUTER JOIN LD0V0Q01 AS Q10 ON Q10.KODTYP = 'LNOVRIG3' AND Q10.KOD = U10.OVRIG3
LEFT OUTER JOIN LD0V0J01 AS J01 ON J01.ORGID = U10.ORGID AND J01.ORGENHNR = U10.ORGENHNR
LEFT OUTER JOIN LD0VAA0OMRADENKO OMR ON A.NYCKKOD = OMR.NYCKKOD 
LEFT OUTER JOIN LD0V0Q01 AS Q7 ON Q7.KODTYP = 'OMRÅDE' AND Q7.KOD = OMRADE
LEFT OUTER JOIN LD0V5U99 AS U99 ON U99.NIVA4_EXTKOD = U10.YRKEAVSLUT_2012
;
