How can I determine the status of a job?

前端 未结 14 2301
佛祖请我去吃肉
佛祖请我去吃肉 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 03:06

    SELECT sj.name
      FROM msdb..sysjobactivity aj
      JOIN msdb..sysjobs sj
        on sj.job_id = aj.job_id
     WHERE aj.stop_execution_date  IS NULL     -- job hasn't stopped running
       AND aj.start_execution_date IS NOT NULL -- job is currently running
       AND sj.name = ''
       AND NOT EXISTS( -- make sure this is the most recent run
                       select 1
                         from msdb..sysjobactivity new
                        where new.job_id = aj.job_id
                          and new.start_execution_date > aj.start_execution_date ) )
    print 'running'
    

提交回复
热议问题