Search code examples
sql-serverbatch-filejobs

SQL Server start job at specific step using bat script


I am trying execute the SQL Server job using a batch command. I use this command to call a job.

osql -S “[SQL SERVER NAME]” -E -Q”exec msdb.dbo.sp_start_job ‘[SQL JOB NAME]‘”

But I want to skip the first 4 steps, instead I want to start the job from step 5.


Solution

  • You have to use step_name parameter :

    EXEC msdb.dbo.sp_start_job @job_name = 'your_job_name', @step_name='step_name'
    

    enter image description here

    Example: EXEC msdb.dbo.sp_start_job @job_name = 'myJob', @step_name='Insert into TGR0' to start from step 2.