USE [DD_ECM]
GO

/****** Object:  View [dbo].[VWCUST_RPTERGEBNISBERICHT_HEAD]    Script Date: 21.03.2024 17:04:48 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO





CREATE VIEW [dbo].[VWCUST_RPTERGEBNISBERICHT_HEAD] as
SELECT DISTINCT

	BA.dwDocID as DocID,
	CONVERT(date,COALESCE(EML.EMAIL_DATE,CAST(CONVERT(varchar(20),ba.decCreationTime) as CHAR(8)))) [DatumIn],
	CONVERT(date,CAST(ba.dwdate09 AS char(8))) AS Belegdatum,
	vec_KRED.szValue as KreditorNummer,
	ba.sztext08 AS KreditorName_Lang,
	ba.sztext08 AS KreditorName,
	ba.sztext19 as RechnungNr,
	COALESCE(ba.sztext36,'NONE') as Referenz,
	ba.lfFloat10 as Nettobetrag,
	ba.lfFloat11 as Bruttobetrag,

	'1999-12-24' Zahlungsziel,
	'4711' as Mandant,
	'Mandant1' as [Mandant Name],
	'4711' as Kostenstelle,
	'4712' as BestellNr,
	COALESCE(eml.EMAIL_FROM,'') as Absender,
	'' as [Finaler Freigeber]
FROM 
	windream60.dbo.BaseAttributes BA LEFT join 
	TBEMLP_HISTORY EML ON BA.szText07 = EML.EMAIL_MSGID LEFT join
	(Select dwDocID, szValue From windream60.dbo.Vector where dwAttrID = 10010) vec_KRED ON BA.dwDocID = vec_KRED.dwDocID
--	WHERE 
--	ba.dwDocID = 785040	




GO


