SQL Server Performance Forum – Threads Archive
how to execute job after another job using alerts?Hello, please help me with this problem… Thanks.
In Management Studio, under SQL Server Agent, expand Alerts. Right-click the alert you want, click Response, in there there is an option to Execute a Job as a response.
Yes, I know about it, but what event is responsible for job execution success?
If you perform errorhandling in the 1st job (the one fired by the alert) either in script, or in an sp that the job executes, you can control your logic. You don’t need to rely on the success/fail attributes of the 1st job, which is what I think, you’re thinking. If you use proper errorhanldling in the first and execute the second job via sp or script from the first, it’ll work fine.
If I underustood your question correctly…<br /><br />You can check the job step success using sysjobhistory table… if you step is successful then you can execute another job using sp_start_job…<br /><br />If exists (select 1 from msdb..sysjobhistory where step_id = <><br />and status = 1 and job_id in (select job_id from msdb..sysjobs where name = <job name><img src=’/community/emoticons/emotion-5.gif’ alt=’‘ /><br />begin<br />exec sp_start_job <second job name><br />end<br /><br /><br />MohammedU.<br />Moderator<br />SQL-Server-Performance.com