HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

Calling a SQL Server job within another job

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
sqlwithinanotherservercallingjob

Problem

Is it possible to call a SQL Server job to run within another job?

I know we can add all steps of Job 1 to Job 2, but I prefer not to do that. First the Job 2 is already quite big and second I couldn't find a copy-paste option to copy steps between jobs, so it would be time consuming to add the steps manually.

Any suggestion is appreciated.

Solution

Option 1

In Job2, create a job step of type TSQL Command. In the contents, have it run the existing job (sp_start_job)

EXECUTE msdb.dbo.sp_start_job 'Job1'


That is going to run asynchronously, thus after it starts calls the stored procedure, it will return and perform the next step in the job. It will not wait for that started job to complete. If the called job fails, it will not percolate back to the invoking job.

Option 2

Right click on Job1 and script to new query window. Repeat that with Job2 and then thread the job steps from 1 into 2 as/where needed. Far less clicking than recreating the wheel and hopefully less error prone.

Code Snippets

EXECUTE msdb.dbo.sp_start_job 'Job1'

Context

StackExchange Database Administrators Q#31104, answer score: 17

Revisions (0)

No revisions yet.