we have a sql server agent
job
which is running two sql servant jobs
.The job
is designed in the way that the second job
will wait
till the first job completed. But sometimes the wait
is not working and it causes both jobs ends up running at same time. This causes failure of both jobs
. We uses below code for waiting
mechanism.
WHILE
(
SELECT COUNT(*) AS cnt
FROM msdb.dbo.sysjobs J
INNER JOIN msdb.dbo.sysjobactivity JA
ON J.job_id = JA.job_id
WHERE start_execution_date IS NOT NULL
AND stop_execution_date IS NULL
AND J.name = "first job name"
AND last_executed_step_date > DATEADD(DD,-1,GETDATE())--//Added to bypass historical corrupt data
) > 0
BEGIN
--WAIT
WAITFOR DELAY '00:01';
END
any suggestion why this is not working sometimes?