Solved

How can you force a script to pause until sp_start_job has finished?

Posted on 2004-08-11
3
464 Views
Last Modified: 2012-06-27
I have a page of scripts, the first of which is an sp_start_job which copies over the data for the rest of the scripts to run off.  Right now, the sp_start_job procedure ends after the other scripts have already run.  I checked BOL and found no variable for sp_start_job to force it to finish efore proceeding.  How can I accomplish this or is there a better work around.  Right now, all I'm going to be able to do is split the script up on different pages and use a javascript timer to create a pause, but that's not ideal for a number of reasons, obviously.
0
Comment
Question by:fairoakian
  • 2
3 Comments
 
LVL 17

Expert Comment

by:BillAn1
Comment Utility
sysjobhistory has a run_status column. You can check this to see when the job has completed
0
 
LVL 17

Accepted Solution

by:
BillAn1 earned 301 total points
Comment Utility
here's how you could use it :

while exists (
select 1
from msdb..sysjobhistory jh join msdb..sysjobs j
on jh.job_id = j.job_id and name = @myjob and runstatus = 4)
begin
     ' twiddle your thumbs.....
end
0
 

Author Comment

by:fairoakian
Comment Utility
Should have placed this in the SQL Server section, but got a great answer anyway.  Thanks.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now