IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME = 'LD0V0CONVERTEDDOCUMENTS')
BEGIN
DROP VIEW LD0V0CONVERTEDDOCUMENTS
END
;

CREATE VIEW LD0V0CONVERTEDDOCUMENTS AS 
select 
T40.DOKUMENTNR,
T40.AEVERKNR,
T40.INSNR,
T40.AGARNR,
T40.DDATUM,
T40.DRUBRIK,
T40.DOKNAMN,
T40.LOSENORD,
T40.LAGRING,
T40.DOKTYP,
T40.DOKMALL,
T40.LAGE,
T40.SCATYP,
T40.SCASKYDD,
T40.UPDDAT,
T40.UPDSIGN,
T40.UTLINSNR,
T40.DBENAMN,
T40.DOCTYPE,
T40.ACTIVE,
Q01.KLARTEXT AS KODTYP_T
from LD0V0T40 T40
LEFT JOIN LD0V0Q01 Q01 ON Q01.KODTYP = 'DOKTYP' AND Q01.KOD = T40.DOKTYP
;