IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME='LD0VAA0LMInternshipOrganizer')
BEGIN
DROP VIEW LD0VAA0LMInternshipOrganizer
END
;

CREATE VIEW LD0VAA0LMInternshipOrganizer
AS 
SELECT
 U50.*
,Q1.KLARTEXT AS HUVUDMAN_T
,Q2.KLARTEXT AS FORVALTNING_T
,Q3.KLARTEXT AS ANSVAR_T
,Q4.KLARTEXT AS VERKSAMHET_T
,Q5.KLARTEXT AS ORGANISATIONNR_T

FROM LD0V0U50 AS U50 
LEFT OUTER JOIN LD0V0Q01 AS Q1 ON Q1.KODTYP = 'LNHUVUDMAN' AND U50.HUVUDMAN = Q1.KOD
LEFT OUTER JOIN LD0V0Q01 AS Q2 ON Q2.KODTYP = 'LNFORVALTN' AND U50.FORVALTNING = Q2.KOD
LEFT OUTER JOIN LD0V0Q01 AS Q3 ON Q3.KODTYP = 'LNANSVAR' AND U50.ANSVAR = Q3.KOD
LEFT OUTER JOIN LD0V0Q01 AS Q4 ON Q4.KODTYP = 'LNANVERK' AND U50.VERKSAMHET = Q4.KOD
LEFT OUTER JOIN LD0V0Q01 AS Q5 ON Q5.KODTYP = 'LNORGANIS' AND U50.ORGANISATIONNR = Q5.KOD
;