DROP VIEW LD0VAA0LMEnrollment
;

CREATE VIEW LD0VAA0LMEnrollment
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
,J01.NAMN  AS  ORGENH_T
FROM LD0V0U10 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 LD0V0J01 AS J01 ON J01.ORGID = U10.ORGID AND J01.ORGENHNR = U10.ORGENHNR
;
