sql run scheduled task and check for completion

  • Hello,

    I am looking to create a Stored Procedure that simply runs a Scheduled Task that they knows when the job has completed.

    To call the Job I am using:

    EXEC msdb.dbo.sp_start_job @job_name='MY_JOB_NAME'

    As a next step is there a way to check if the Scheduled Job has completed and keep checking until the job completes via a query?

  • Slight rewrite of http://qa.sqlservercentral.com/Forums/Topic1733134-3077-1.aspx

    --declare @JobName sysname ='Your Job Name'

    SELECT *

    FROM msdb.dbo.sysjobs_view j

    JOIN msdb.dbo.sysjobactivity a

    ON (j.job_id = a.job_id)

    JOIN (SELECT MAX(session_id) AS session_id FROM msdb.dbo.syssessions) s

    ON s.session_id = a.session_id

    WHERE j.enabled = 1

    AND a.run_requested_date IS NOT NULL

    AND a.stop_execution_date IS NULL

    --AND j.name = @JobName

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply