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