USE [DD_ECM]
GO

CREATE PROCEDURE [dbo].[PRCUST_ESKALATION_MAIL_NOWMFOLDERSYNC] AS
BEGIN
	DECLARe @COUNT INT
	SET @COUNT = 99

	SELECT @COUNT = COUNT(dwDocID)
	FROM [VWCUST_WM_BASE_ATTRIBUTES_DOCS]
	WHERE [sztext37] = 'Ausgangsrechnung'
	  AND [szText36] is NOT NULL
	  AND [dwDate09] is NULL
	  AND [szText00] is NULL
	  AND [szText39] is NULL
	  AND [szText09] is NULL
	  AND DATEDIFF(MINUTE,CAST(CAST(CONVERT(DATE,CONVERT(VARCHAR(10),dwCreationDate)) AS DATETIME) + CAST(STUFF(STUFF(REPLICATE('0',6-LEN(dwCreation_Time)) + convert(VARCHAR(6),dwCreation_Time),3,0,':'),6,0,':') AS DATETIME) AS DATETIME),GETDATE()) > 60

	IF @COUNT > 0
		BEGIN
			DECLARE @MSGBODY NVARCHAR(1000)
			SET @MSGBODY = 'ACHTUNG: <br>Seit mehr als 60 Minuten werden keine Dateien mehr indexiert.<br>
			Aktuelle Anzahl nicht indexierter Dateien: ' + CONVERT(VARCHAR(4),@COUNT) + '
			Maschine: S-ZLSDMS1 <br>
			Mail erzeugt von Procedure: PRCUST_ESKALATION_MAIL_NOWMFOLDERSYNC '
			PRINT @MSGBODY
			EXEC PREMAIL_NEW_EMAIL 1, 'support-flow@digitaldata.works','ZLS - ToolCollection Eskalation',@MSGBODY,'NoWMFolderSync',99999,0,'System'
		END
END