SQL Server Job Example using sp_start_job

25 pts.
Tags:
SQL Server
I need to use sp_start_job to schedule two jobs in SQL Server: the second job may run only if the first succeeds. 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!

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

exec sp_start_job @job_name='The Second Job'
GO

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.

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Denny Cherry
    Check out my SQL Server blog "SQL Server with Mr Denny" for more SQL Server information.
    66,115 pointsBadges:
    report
  • VINSALA
    Thanks a lot : the first is a very nice solution !
    25 pointsBadges:
    report
  • VINSALA
    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 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following