How do I start a job from a job using msdb.dbo.sp_start_job ?

  • Hi,

    I created a main job that's supposed to execute three other jobs in sequence. The job contains the below three steps

    Step 1

    exec msdb.dbo.sp_start_job @job_name = N'job1', @step_name =N'step1'

    go

    Step 2

    exec msdb.dbo.sp_start_job @job_name = N'job2', @step_name =N'step1'

    go

    Step 3

    exec msdb.dbo.sp_start_job @job_name = N'job3', @step_name =N'step1'

    go

    Each job step works fine but the problem is that step 2 is executed right after step 1 (and step 3 after step 2) without waiting for step 1 to finish.

    The result is that all three jobs run simultaneously instead of after each other.

    What must I do to make this job work the way I want it to ?

    kind regards,

    Walter Grimm

  • Create a sql agent job, with tsql commands as steps, and configure them there.

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle

  • Thanks Henrico,

    The thing is that I already had the three separate jobs and wanted to combine them into one by just creating a job with three steps. I guess that wasn't a good idea.

    As you suggested I created a new job that contains all the T-SQL from the three jobs and this works fine.

    Walter

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply