Return a status or value from sp_start_job

April 30th, 2009 by Mr.M | No Comments »

In my procedure, I’m calling a job on a remote server and if this call fails, I would like the code to handle it accordingly. So if I get a return value or status of 0, the job started successfully. If 1, then it failed to start.

Now I can’t monitor the entire duration of the SQL job on the remote server, I’ll need another process for it.

The code to return a value or status from sp_start_job is as follow:

  1. declare @rnt int
  2. exec @rnt = msdb.dbo.sp_start_job @job_name = 'JOB_NAME'
  3. IF @rnt = 1
  4. begin
  5. --- code to handle the failure
  6. end

Leave a Reply

You must be logged in to post a comment.