Author |
Topic |
DLTaylor
Posting Yak Master
136 Posts |
Posted - 2008-03-25 : 06:24:58
|
I have SQL 2000 SP3I would like to run a number of JOBs via the SQL Server Agent from one Master JOB.When i use the following e.g statement;USE msdbEXEC sp_start_job @job_name = 'My_Job1'USE msdbEXEC sp_start_job @job_name = 'My_Job2'As you might expect all my JOBs start at once - however i'd like the jobs to start only after the preceding JOB has completed. Does anyone know an easy way to achieve this?(Hope the T-SQL is the correct forum for this question)Any ideas will be most appreciated.Thanks |
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-03-26 : 22:18:36
|
Put them in separate steps in main job. |
 |
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2008-03-27 : 08:35:44
|
also gives you the option of putting in some failure/success logicJack Vamvas--------------------Search IT jobs from multiple sources- http://www.ITjobfeed.com |
 |
|
DLTaylor
Posting Yak Master
136 Posts |
Posted - 2008-03-31 : 06:03:15
|
Thanks for your replies;Even when you place the EXEC sp_start_job in a separate step it will still continue to start all the JOBS in one swoop - without waiting for the job to complete with success. |
 |
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-03-31 : 23:24:40
|
What I meant is put all those jobs as separate step in single job, not call sp_start_job. |
 |
|
DLTaylor
Posting Yak Master
136 Posts |
Posted - 2008-05-13 : 11:18:39
|
Sorry I haven’t picked up on this thread for a while – it’s a long story...I have tried putting the Jobs into separate steps which still results in all Jobs starting one after other (the setup doesn’t recognise each job takes x mins to complete).(As some of the individual Jobs I wish to schedule have up to 50 internal steps I want to keep them separate)Is it possible to have one master Job that waits for My_Job1 to complete before starting My_Job2 etc…?Any advice will be much appreciated,Thanks again,Dan |
 |
|
cat_jesus
Aged Yak Warrior
547 Posts |
Posted - 2008-05-13 : 12:29:41
|
How about creating a status table and writing to it when each job is finished? You would also have to check the table at the beginning step of each job. Set the step to fail if it's not clear to start yet and retry X times for X minutes.An infinite universe is the ultimate cartesian product. |
 |
|
DLTaylor
Posting Yak Master
136 Posts |
Posted - 2008-05-15 : 10:56:33
|
Ive written the code below to build a log table but as im no programmer can you advise on how to write the code to change the table status.------------------------------------------SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE xJobLog(JobName nvarchar(50),DateUpdated smalldatetime,StatusFlag char(1) )GOSET ANSI_PADDING OFF--Status N = Job not yet runInsert into xJobLogselect 'Job1', { fn NOW() }, 'N' UNION allselect 'Job2', { fn NOW() }, 'N' UNION allselect 'Job3' , { fn NOW() } , 'N' UNION allselect 'Job4' , { fn NOW() }, 'N' UNION allselect 'Job5' , { fn NOW() }, 'N' UNION allselect 'Job6' , { fn NOW() }, 'N' UNION allselect 'Job7' , { fn NOW() } , 'N'-----------------------------------------------In then meantime i will keep trying myself.ThanksDan |
 |
|
DLTaylor
Posting Yak Master
136 Posts |
Posted - 2008-05-15 : 11:43:00
|
dont know if this helps anyone...I have got around the problem by placing a delay on the job - WAITFOR DELAY (neat function)not ideal but is a way of delaying the job...Thanks-----------------------------------BEGIN--wait 1 minWAITFOR DELAY '00:01';USE msdbEXEC sp_start_job @job_name = 'JOB1'END;GoBEGIN--wait 2 minWAITFOR DELAY '00:02';USE msdbEXEC sp_start_job @job_name = 'JOB2'END;GoBEGIN--wait 6 minWAITFOR DELAY '00:06';Use msdbEXEC sp_start_job @job_name = 'JOB3'END;Go |
 |
|
X002548
Not Just a Number
15586 Posts |
|
cat_jesus
Aged Yak Warrior
547 Posts |
Posted - 2008-05-16 : 10:16:05
|
Try this in a query windowCREATE TABLE #xJobLog(JobName nvarchar(50),DateStarted smalldatetime null,DateFinished smalldatetime null )GOSET ANSI_PADDING OFF--Status N = Job not yet runInsert into #xJobLogselect 'Job1', { fn NOW() }, null UNION allselect 'Job2', { fn NOW() }, null UNION allselect 'Job3' , { fn NOW() } , null UNION allselect 'Job4' , { fn NOW() }, null UNION allselect 'Job5' , { fn NOW() }, null UNION allselect 'Job6' , { fn NOW() }, null UNION allselect 'Job7' , { fn NOW() } , nullselect * from #xJoblog-----------------------------------------------if (select count(*) from #xJoblog where jobname = 'Job1' and DateStarted = (select max(datestarted) from #xJoblog where Jobname = 'Job1' ) and DateFinished is null) = 1 raiserror ('Job1 is not finished yet', 16, 1)drop table #xJoblog Use something like this as a first step in the job that is dependent on Job1 finishing. Set the step to retry X number of times with X minute intervals.This isn't exactly how I'd do it, but hopefully it will give you an idea on how to solve your problem.An infinite universe is the ultimate cartesian product. |
 |
|
DLTaylor
Posting Yak Master
136 Posts |
Posted - 2008-05-27 : 05:05:35
|
Thanks Cat_Jesus, have adopted your methodology to resolve the problem.….its a lot more practical than the WAITFOR DELAY function :) |
 |
|
|