DROP VIEW LD0VAA0DossierNote
;
CREATE VIEW LD0VAA0DossierNote
AS
SELECT        T41.DOKUMENTNR, T41.AGARNR, T41.AGARTYP, T41.DDATUM, T41.DRUBRIK, T41.DOKID, T41.UPDDAT, T41.UPDSIGN, T41.UTLINSNR, T41.DOCTYPE, T41.ACTIVE, 
                         T41.DOKTYP, T41.PERSONNR, T41.DELETED, T41.LNDOKTYP, T41.HUVUDOBJTYP, T41.HUVUDOBJNR, T41.VERSIONNR, T41.ANSVHAND, T41.ANSVTITEL, 
                         T41.ANTDOKTYP, T41.EBREV_SENDDATE, T41.EBREV_SENDTIME, T41.EBREV_SENDSIGN, T41.EBREV_SENDACK, T41.HANDELSEDATE, T41.LOCKED, 
                         T41.LOCKDATE, T41.LOCKSIGN, Q01.KLARTEXT DOKTYP_T, TXT.TEXTID, Q01.XNUM28 CANCHANGEOCCURENCEDATE, Q01.XNUM4 BLANKETT,
						 T41.LIFECARE_CREATED, C.AKTPNR INV_PNR, A1.NAMN INV_NAMN, C20.AKTPNR SERV_PNR, A2.NAMN SERV_NAMN
FROM LD0V0T41 T41 
INNER JOIN LD0V0Q01 Q01 
ON T41.ANTDOKTYP = Q01.KOD 
AND Q01.KODTYP = 'ANTTYP' 
INNER JOIN GA1V0TXT TXT 
ON '7255.' + CONVERT(VARCHAR(32), T41.DOKUMENTNR) = TXT.OBJEKTID 
AND TXT.DELETED = 0 
LEFT JOIN LD0VLC C 
ON C.AEVERKNR = T41.AGARNR 
AND T41.AGARTYP = 42
LEFT JOIN LD0VLC20 C20 
ON C20.INSNR = T41.AGARNR 
AND T41.AGARTYP = 41
LEFT JOIN LD0V0A A1 
ON C.AKTPNR = A1.PNR
LEFT JOIN LD0V0A A2 
ON C20.AKTPNR = A2.PNR
WHERE T41.AGARTYP IN (41, 42)
;