-- Reset any Application that DataTTL has expired since the last scan attempt
UPDATE dbo.[ApplicationScanHistory]
SET [AttemptCount] = @MaxFailures-1
WHERE [ApplicationScanHistoryID]IN
(
SELECT [ApplicationScanHistoryID]
FROM [ApplicationScanHistory] ash WITH( NOLOCK )
JOIN [Application] a WITH( NOLOCK ) ON a.[ApplicationID] =ash.[ApplicationID]
WHERE ([ServiceTypeEnumID] = @ServiceTypeEnumID
AND a.[DataTTL] is not null
AND DATEADD(DAY, a.[DataTTL], ash.[LastAttemptDate]) <= @CurrentDate)
AND ash.[AttemptCount] >= @MaxFailures); |