
ALTER VIEW LD0V0CDOCUMENTS_AKTUALISERING
AS
SELECT
    T41.DOKUMENTNR, T41.AGARNR, T41.AGARTYP, T41.DRUBRIK, T41.DOKTYP, T41.ANTDOKTYP,
    AKTUAL.KLARTEXT AS DOCUMENTTYPETEXT, T41.DDATUM, T41.DELETED, T41.LOCKED, 
    T41.LOCKDATE, T41.LOCKSIGN, T41.HANDELSEDATE, T41.UPDDAT, UPPER(T41.UPDSIGN) AS CASEWORKERID,
    CASEWORKER.NAMN AS CASEWORKERNAME, ORG.NAMN AS ORGANIZATIONNAME, ORG.ORGENHNR AS ORGANIZATIONID, 
    T41.PERSONNR, PERSON.NAMN AS PERSONNAME, PERSON.KUNDNUMMER AS PERSONKEY, B.TYPNR AS AKTUALTYPECODE,
    Q1.KLARTEXT AS AKTUALTYPETEXT, 0 AS ISINVESTIGATIONORIMPLEMENTATION, T41.LIFECARE_CREATED, AKTUAL.XNUM4 AS BLANKETT

FROM LD0V1T41 T41
    INNER JOIN LD0V0H AS H ON H.AKTUALNR = T41.AGARNR AND T41.AGARTYP = 20 AND T41.DOKTYP > 0
    LEFT OUTER JOIN LD0V0C AS C ON C.AEVERKNR = H.AEVERKNR
    LEFT OUTER JOIN LD0V0B AS B ON B.AKTNR = C.AKTNR
    LEFT OUTER JOIN LD0V0Q01 AS Q1 ON Q1.KODTYP = 'AKTTYP' AND Q1.KOD = B.TYPNR 
    LEFT OUTER JOIN LD0V0Q01 AS AKTUAL ON T41.DOKTYP = AKTUAL.KOD AND AKTUAL.KODTYP = 'TYPDOK' 
    LEFT OUTER JOIN LD0V0I AS CASEWORKER ON T41.UPDSIGN = CASEWORKER.HAND 
    LEFT OUTER JOIN LD0V0A AS PERSON ON T41.PERSONNR = PERSON.PNR 
    LEFT OUTER JOIN LD0V0J01 AS ORG ON H.ORGENHNR = ORG.ORGENHNR
;