CREATE OR ALTER VIEW LD0VAA0EServiceAktualiseringSummary
AS
SELECT
    H.AKTUALNR,
    H.INSNR,
    H.AEVERKNR,
    H.BESLUTNR,
    H.AKTUAL,
    H.AKTUALTYP,
    H.ADATUM,
    H.AKTNR,
    H.PNR,
    H.REGTID,
    H.SPOTCHECK,
    P.NAMN,
    P.KUNDNUMMER,
    C.STARTDAT  AS INV_STARTDAT,
    C.STOPDAT   AS INV_STOPDAT,
    QC.KLARTEXT AS INV_AEVERKTYP_T,
    QC.XNUM40   AS WORKFLOW_T_C,
    C20.FOMDAT  AS SERV_FOMDAT,
    C20.TOMDAT  AS SERV_TOMDAT,
    QC20.KLARTEXT AS INSTYP_T,
    QC20.XNUM40 AS WORKFLOW_T_C20,
    T.XNUM40    AS WORKFLOW_T,
    T1.KLARTEXT AS WORKFLOW_TEXT
FROM LD0V0H AS H
LEFT JOIN LD0P0A AS P
    ON H.PNR = P.PNR
INNER JOIN LD0V0Q01 AS T
    ON T.KODTYP = 'AKTUAL'
    AND T.KOD = H.AKTUAL
LEFT JOIN LD0V0Q01 AS T1
    ON T1.KODTYP = 'LCFLOW'
    AND T1.KOD = T.XNUM40
LEFT JOIN LD0P0C AS C
    ON C.AEVERKNR = H.AEVERKNR
LEFT JOIN LD0V0Q01 AS QC
    ON QC.KODTYP = 'UTREDTYP'
    AND QC.KOD = C.AEVERKTYP
LEFT JOIN LD0P0C20 AS C20
    ON C20.INSNR = H.INSNR
LEFT JOIN LD0V0Q01 AS QC20
    ON QC20.KODTYP = 'INSATS'
    AND QC20.KOD = C20.INSTYP;
GO

GRANT ALL ON LD0VAA0EServiceAktualiseringSummary TO LD0ROANV;
GO