DROP VIEW LD0VAA0SEARCHDOCUMENTS
;
CREATE VIEW LD0VAA0SEARCHDOCUMENTS
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,
T41.SKAPADAVGALLRING,
T41.PUBLISH_DATE,
T41.PUBLISH_MOBIL,
T41.PUBLISH_EMAIL,
T41.LIFECARE_CREATED,
T41.TEMPLATE,
T41.RESPOND_DATE,
T41.PUBLISH_HANDL,
T41.PUBLISH_ORGID,
T41.PUBLISH_ORGENHNR,
T41.ACTNOTETYP,
T41.RESPOND_WANTED,
T41.PUBLISH_STATUS,
Q01_1.KLARTEXT AS ANTTYP_T,
Q01_2.KLARTEXT AS DOKTYP_T,
Q01_2.XNUM4 AS BLANKETT,P.NAMN,
P.KUNDNUMMER AS PERSONKEY
FROM LD0V0T41 AS T41 
JOIN LD0V0A AS P 
ON T41.PERSONNR = P.PNR 
LEFT OUTER JOIN LD0V0Q01 AS Q01_1 ON T41.ANTDOKTYP = Q01_1.KOD AND Q01_1.KODTYP = 'ANTTYP' 
LEFT OUTER JOIN LD0V0Q01 AS Q01_2 ON T41.DOKTYP = Q01_2.KOD AND Q01_2.KODTYP = 'TYPDOK' 
WHERE (T41.DOKTYP > 0 OR T41.LNDOKTYP > 0) AND (T41.DELETED = 0) AND (T41.AGARTYP IN (20,21,23,25,39,40)) 
;