USE [DD_ECM]
GO

/****** Object:  View [dbo].[VWCUST_PM_PROFILE_TODO]    Script Date: 21.03.2024 17:03:12 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



-- DIE FUNKTION "[PRCUST_CREATE_PM_REMINDER_MAILS]" UND DER VIEW [VWCUST_PM_PROFILE_TODO] WERDEN AKTUELL NICHT VERWENDET! STAND 31.10.2021

-- TSQL View provides procedure with the data/ the info which users should be informed

-- Stand: MK // 25.10.2021

CREATE VIEW [dbo].[VWCUST_PM_PROFILE_TODO] 
AS
	SELECT 
		LOWER(T5.EMAIL) as Email, 
		Count(T1.DOC_ID) Anzahl,
		T1.PROFIL_ID AS ProfileID, 
		T2.TITLE,
		'Aufgabe' as PType,
		Case T1.PROFIL_ID 
			When 1 then 1 
			else 4 
		end as OSequence 

	FROM [TBPM_PROFILE_FILES] as [T1]
		INNER JOIN [TBPM_PROFILE] as [T2]						ON T1.PROFIL_ID = T2.GUID
		INNER JOIN [windream60].[dbo].[BaseAttributes] as [T3]	ON T1.DOC_ID	= T3.dwDocID
		INNER JOIN [TBPM_PROFILE_USER] as T4					ON T2.GUID		= T4.PROFIL_ID
		INNER JOIN [TBDD_USER] as T5							ON T4.USER_ID	= T5.GUID

	WHERE
		T3.sztext22 = t5.USERNAME and
		T1.DOC_ID not in (SELECT DOC_ID FROM TBPM_PROFILE_FILES WHERE ACTIVE = 0 or IN_WORK = 1 or EDIT = 1)

	GROUP BY LOWER(T5.EMAIL),T1.PROFIL_ID, T2.TITLE


--	Tabelle gefüllt mit:
--	INSERT INTO [DD_ECM].[dbo].[TBPM_PROFILE_USER]([PROFIL_ID],[USER_ID])
--	SELECT 4 as [PROFIL_ID], [GUID] as [USER_ID]
--	FROM   [TBDD_USER]
--	WHERE  [name] not in ('Schellhase','') and len(email) > 2




GO


