?
Solved

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

Posted on 2004-08-11
3
Medium Priority
?
481 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
ID: 11778701
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 1204 total points
ID: 11778749
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
ID: 11779254
Should have placed this in the SQL Server section, but got a great answer anyway.  Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 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