Some of the steps are quite involved so I would prefer to keep them out of the job steps themselves.
I have a solution to my problem, if you want to take a look...
This sp checks to see if a job is running....
CREATE PROCEDURE JobRunning
@jobname nvarchar(50)
AS
Declare
@jobid AS uniqueidentifier,
@State As int
--get job id from name
SELECT @jobid = job_id
From sysjobs
WHERE name = @jobname
--create temp table
create table #enum_job (
Job_ID uniqueidentifier,
Last_Run_Date int,
Last_Run_Time int,
Next_Run_Date int,
Next_Run_Time int,
Next_Run_Schedule_ID int,
Requested_To_Run int,
Request_Source int,
Request_Source_ID varchar(100),
Running int,
Current_Step int,
Current_Retry_Attempt int,
State int
)
--insert job details into temp table by running extended job (must supply a couple paramaters, <is sysadmin 1 or 0>, and job owner
insert into #enum_job
execute master.dbo.xp_sqlagent_enum_jobs 1,'PADRES\Sysadmin'
--insert execution state into variable
SELECT @State = #enum_job.State FROM #enum_job
WHERE #enum_job.job_id = @jobid
drop table #enum_job
--if job is running, return 1, else return 0
if @State < 4
RETURN 0
ELSE
RETURN 1
GO
I start the job with this sp. It runs the above sp to see if it's running and when it stops running, it checks to see if it's successful. If it is successful, the MASTER job continues, if not, the MASTER job stops. Pretty cool, I think...
CREATE PROCEDURE StartJob @jobname varchar(50) AS
--start job
exec msdb.dbo.sp_start_job @job_name = @jobname
DECLARE @return_status int
DECLARE @outcome int
DECLARE @jobid uniqueidentifier
DECLARE @outcome_message nvarchar(25)
SET @return_status = 0
SET @outcome = 0
SET @outcome_message = NULL
--get job id from job name
SELECT @jobid = job_id
From msdb.dbo.sysjobs
WHERE name = @jobname
--check to see if job is running, if it's idle, exit while loop
WHILE @return_status = 0
BEGIN
WAITFOR DELAY '000:00:30'
exec @return_status = msdb.dbo.JobRunning @jobname --check to see if job is idle 0 means not idle, 1 means idle
END
--check to see if last outcome was successful
SELECT @outcome = last_run_outcome FROM msdb.dbo.sysjobservers WHERE job_id = @jobid
--if last outcome is not successful stop job
if @outcome <> 1
BEGIN
exec msdb.dbo.sp_stop_job @job_name = 'StartAllJobTest'
END
GO