How can I determine the status of a job?

前端 未结 14 2275
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 02:36

I have a Stored procedure which schedules a job. This Job takes a lot of time to get completed (approx 30 to 40 min). I need to get to know the status of this Job. Below det

14条回答
  •  眼角桃花
    2020-11-30 02:46

    -- Microsoft SQL Server 2008 Standard Edition:
    IF EXISTS(SELECT 1 
              FROM msdb.dbo.sysjobs J 
              JOIN msdb.dbo.sysjobactivity A 
                  ON A.job_id=J.job_id 
              WHERE J.name=N'Your Job Name' 
              AND A.run_requested_date IS NOT NULL 
              AND A.stop_execution_date IS NULL
             )
        PRINT 'The job is running!'
    ELSE
        PRINT 'The job is not running.'
    

提交回复
热议问题