CREATE OR ALTER VIEW LD0VAA0ActivityLMStaffed AS
SELECT DISTINCT
    U35.*,
    Q1.KLARTEXT AS STATUS_T,
    U60.BENAMNING AS PRAKPROJ_T,
    U10.PERSONNR AS U10_PNR,
    A.NAMN AS PERSON_NAMN,
    A.KUNDNUMMER AS PERSON_KUNDNUMMER,
    I.HAND AS HAND,
    I.NAMN AS HAND_T,
    U34.PLANNR AS U34_PLANNR,
    U34.VERSIONNR AS U34_VERSIONNR,
    U34.PLANSTART AS U34_PLANSTART,
    U34.PLANSLUT AS U34_PLANSLUT,
    U34.AKTIVITET AS U34_AKTIVITET,
    Q1_2.KLARTEXT AS U34_AKTIVITET_T,
    Q1_3.KLARTEXT AS U34_AKTIVITET_TYP_T,
    Q1_3.XNUM7 AS AKTIVITETSCHEMATILLATEN
FROM LD0V0U35 AS U35
    LEFT OUTER JOIN LD0V0U60 AS U60 ON U35.PRAKPROJNR = U60.PRAKPROJNR
    LEFT OUTER JOIN LD0VYU34 AS U34 ON U35.PLANAKTIVITETNR = U34.PLANAKTIVITETNR
    LEFT OUTER JOIN LD0VYU30 AS U30 ON U34.PLANNR = U30.PLANNR
    LEFT OUTER JOIN LD0VYU10 AS U10 ON U30.INSKRIVNINGSNR = U10.INSKRIVNINGSNR
    INNER JOIN LD0V0A AS A ON U10.PERSONNR = A.PNR
    LEFT OUTER JOIN LD0V0I AS I ON U34.HAND = I.HAND
    LEFT OUTER JOIN LD0V0Q01 AS Q1 ON Q1.KODTYP = 'LNSTATUS' AND U35.STATUS = Q1.KOD
    LEFT OUTER JOIN LD0V0Q01 AS Q1_2 ON Q1_2.KODTYP = 'LNAKTIV' AND U34.AKTIVITET = Q1_2.KOD
    LEFT OUTER JOIN LD0V0Q01 AS Q1_3 ON Q1_3.KODTYP = 'LNAKTIVTYP' AND U34.AKTIVTYP = Q1_3.KOD
WHERE STATUS = 2
GO
GRANT SELECT ON LD0VAA0ActivityLMStaffed TO LD0ROANV
GO