IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME='LD0V0CUSTOMERDOCUMENTWITHLINKEDDATA')
BEGIN
DROP VIEW LD0V0CUSTOMERDOCUMENTWITHLINKEDDATA
END
;
CREATE VIEW LD0V0CUSTOMERDOCUMENTWITHLINKEDDATA
AS
SELECT        
LD0P0CUSTOMERDOCUMENT.*, 
LD0P0CUSTOMERDOCUMENTLINKEDDATA.ENCOUNTERID, 
LD0P0CUSTOMERDOCUMENTLINKEDDATA.PROCESSID
FROM            
LD0P0CUSTOMERDOCUMENT INNER JOIN
LD0P0CUSTOMERDOCUMENTLINKEDDATA 
ON LD0P0CUSTOMERDOCUMENT.ID = LD0P0CUSTOMERDOCUMENTLINKEDDATA.CUSTOMERDOCUMENTID
;