26 lines
837 B
Transact-SQL
26 lines
837 B
Transact-SQL
DECLARE @snapshot_in_error BIT = 0;
|
|
declare @today datetime = DATEADD(DAY,0,DATEDIFF(DAY,0,CURRENT_TIMESTAMP))
|
|
|
|
SELECT h.*
|
|
FROM msdb.dbo.sysjobs j
|
|
JOIN msdb.dbo.sysjobhistory h ON h.job_id = j.job_id
|
|
WHERE j.name ='D00480 - ActivePos_read Snapshot'
|
|
AND msdb.dbo.agent_datetime(h.run_date, h.run_time) > @today
|
|
AND h.run_status = 0 --there was an error
|
|
AND NOT EXISTS(
|
|
--there is not record not in error after the one found above
|
|
SELECT 1
|
|
FROM msdb.dbo.sysjobhistory h2
|
|
WHERE h2.job_id = h.job_id
|
|
AND msdb.dbo.agent_datetime(h2.run_date, h2.run_time) > msdb.dbo.agent_datetime(h.run_date, h.run_time)
|
|
AND h2.run_status <> 0
|
|
and h2.step_id = 0
|
|
)
|
|
ORDER BY h.run_time DESC ;
|
|
|
|
SELECT @snapshot_in_error = @@ROWCOUNT;
|
|
|
|
if @snapshot_in_error = 1
|
|
begin
|
|
exec msdb.dbo.sp_start_job @job_name='D00480 - ActivePos_read Snapshot'
|
|
end |