25 pts.
 SQL Server Job Example using sp_start_job
I need to use sp_start_job to schedule two jobs in SQL Server : the second job may run only if the first succeds. Can you give me an example of a job running this store procedure to do this ? Is there another method to do this in SQL Server ? Thanks in advance !

Software/Hardware used:
ASKED: February 12, 2008  6:44 PM
UPDATED: April 22, 2011  4:31 PM

Answer Wiki:
I've used this method many times. Simply add another step to the first job, with the command type of T/SQL command and put something to this effect in the command box. <pre>exec sp_start_job @job_name='The Second Job' GO</pre> If the second job will run every time that the first job runs, then why not take the job steps from the second job and add them to the first job. This was it's a single seamless job. If you need the second job to be able to be run seperatly from the first then keeping them as two jobs will be the best bet. wow rotten answer, the jobs return a 1 or 0 you just need to capture the return code, then place that in an if statement.
Last Wiki Answer Submitted:  April 22, 2011  4:31 pm  by  Denny Cherry   64,550 pts.
All Answer Wiki Contributors:  Denny Cherry   64,550 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.

 64,550 pts.

 

Thanks a lot : the first is a very nice solution !

 25 pts.

 

I think the first solution is better!
I have problems in mainteinance of two jobs (they are modified by automatic setups).
So I think the best solution is executing a batch running two times sp_start_job (one for the first job and one for the second job).
The second job can execute only if the first runs succesfully.
I don’ t know if this is possible (now I try some exemple).
Thank in advance for every hint!

 25 pts.