How to know the job status in stored procedure

92 Views Asked by At

I want to know the job status for specific job and based on specific job status I need to do something. I don't know how to do it. I just tried by this below code. It does not do nothing.

EXEC msdb.dbo.sp_help_job 
    @job_name = 'CreateIOPlan'  
    @execution_status = 1

IF @job_name = 'CreateIOPlan' AND @execution_status = 1
BEGIN
    EXEC  msdb.dbo.sp_stop_job N'CreateIOPlan' 
END
0

There are 0 best solutions below