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

CREATE VIEW LD0V0COLLECTIVECOPY
AS

SELECT T44.*,
T41FROM.DOKTYP AS DOKTYP,
T41TO.AGARNR AS AGARNRTO,
T41TO.AGARTYP AS AGARTYPTO,
T41TO.TID AS CREATEDTIME,
I1.NAMN AS HANDNAMNTO,
A1.Namn AS NAMETO, 
T41FROM.AGARNR AS AGARNRFROM,
T41FROM.AGARTYP AS AGARTYPFROM,
T41FROM.DRUBRIK AS RUBRIKFROM,
T41FrOM.ANTDOKTYP AS ANTDOKTYP,
T41FrOM.LIFECARE_CREATED AS LIFECARE_CREATED,
I2.NAMN AS HANDNAMNFROM,
A2.Namn AS NAMEFROM
FROM LD0V0T44 T44 
LEFT JOIN LD0V0T41 T41TO ON T44.DOKNRTO = T41TO.DOKUMENTNR
LEFT JOIN LD0V0T41 T41FROM ON T44.DOKNRFROM = T41FROM.DOKUMENTNR
LEFT JOIN LD0V0A A1 ON T44.PNRTO = A1.PNR
LEFT JOIN LD0V0A A2 ON T44.PNRFROM = A2.PNR
LEFT JOIN LD0V0I I1 ON T44.HANDTO = I1.HAND
LEFT JOIN LD0V0I I2 ON T44.HANDFROM = I2.HAND
;
