How to determine if a sql server job is already executing (sp_help_job)

  • I need to find out if a job is running by checking the results of [current_execution_status] through transact sql using this system stored proc: 

    sp_help_job

    @job_name = 'test',

    @execution_status = 1,

    @job_aspect = 'JOB'

    I would like to check the results of [current_execution_status] through transact sql.  If it isn't running then I want to start the job [sp_start_job].  This system stored procedure doesn't have output parameters, so I can't check the values.  Is is possible to use this procedure [sp_help_job] and query the results using transact sql?

    I could run this alternative query

    SELECT instance_id, FROM msdb.dbo.sysjobhistory WHERE job_id = 'abc123'

    and run_status = 1

    and use max(instance_id), but I'm not sure if this is the correct value I am looking for.

    Thanks

    Steve

  • I'll give it a try.  Thanks

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

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