0

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
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • By 'does nothing' do you mean it doesn't start the job as expected? See here on how to get the status of a job: https://robbamforth.wordpress.com/2011/03/08/sql-%E2%80%93-how-to-get-the-status-of-an-sql-job-sp_help_job/ – Nick.Mc Jan 01 '17 at 09:17
  • Procedural code is **highly vendor-specific** - so please add a tag to specify whether you're using `mysql`, `postgresql`, `sql-server`, `oracle` or `db2` - or something else entirely. – marc_s Jan 01 '17 at 09:29
  • I am using sql-server 2008R2 – Shahana Akter Pingkey Jan 01 '17 at 10:31
  • Please go through this link http://stackoverflow.com/questions/200195/how-can-i-determine-the-status-of-a-job – Sreepathi Jan 02 '17 at 10:27

0 Answers0