CREATE VIEW LD0V0CJOURNALNOTES_DOSSIEREVENT
AS 
SELECT 
		ACT.HDATUM DATE, T41.DRUBRIK TITLE, T41.ANSVHAND AUTHOR, B.AKTPNR PERSONID, T41.ANTDOKTYP ANTDOKTYPCODE, 
		T41.DOKUMENTNR DOCUMENTID, T41.ACTNOTETYP ACTNOTETYPCODE, T41.LOCKED LOCKED, B.TYPNR AKTTYPCODE, TXT.TEXTID NOTETEXTID
FROM    LD0V2T41 T41
		INNER JOIN LD0V0B01 ACT ON ACT.HAGNR = T41.DOKUMENTNR AND ACT.HANDELSE = 320
		INNER JOIN LD0V0B B ON ACT.AKTNR = B.AKTNR
		LEFT JOIN GA1V0TXT TXT ON '7255.' + CONVERT(VARCHAR(32), T41.DOKUMENTNR) = TXT.OBJEKTID AND TXT.DELETED = 0 AND RUBRIKID LIKE '7258.Aktanteckning.' + CONVERT(VARCHAR(32), T41.ANTDOKTYP)
WHERE   T41.ANTDOKTYP > 0
;

CREATE VIEW LD0V0CJOURNALNOTES_JOURNALEVENT
AS
SELECT 
		C11.HDATUM DATE, T41.DRUBRIK TITLE, T41.ANSVHAND AUTHOR, C.AKTPNR PERSONID, T41.ANTDOKTYP ANTDOKTYPCODE, 
		T41.DOKUMENTNR DOCUMENTID, T41.ACTNOTETYP ACTNOTETYPCODE, T41.LOCKED LOCKED, B.TYPNR AKTTYPCODE, TXT.TEXTID NOTETEXTID
FROM	LD0V2T41 T41
		INNER JOIN LD0V0C11 C11 ON C11.HAGNR = T41.DOKUMENTNR AND C11.HANDELSE = 320
		INNER JOIN LD0V0C C ON C11.AEVERKNR = C.AEVERKNR
		INNER JOIN LD0V0B B on C.AKTNR = B.AKTNR
		LEFT JOIN GA1V0TXT TXT ON '7255.' + CONVERT(VARCHAR(32),T41.DOKUMENTNR) = TXT.OBJEKTID AND TXT.DELETED = 0 AND RUBRIKID LIKE '7258.Aktanteckning.' + CONVERT(VARCHAR(32), T41.ANTDOKTYP)
WHERE   T41.ANTDOKTYP > 0
;