首頁 > 資料庫 > mysql教程 > 检查SQL Server Job状态

检查SQL Server Job状态

WBOY
發布: 2016-06-07 14:58:12
原創
1575 人瀏覽過

检查SQLServerJob状态 无 exec msdb.dbo.sp_help_job @execution_status=1 select distinct j.Name as "Job Name", j.description as "Job Description", h.run_date as LastStatusDate, h.run_time as LastStatusTime, h.run_duration as LastStatusDuration

检查SQL Server Job状态
exec msdb.dbo.sp_help_job @execution_status=1 
登入後複製
select distinct j.Name as "Job Name", j.description as "Job Description", h.run_date as LastStatusDate, h.run_time as LastStatusTime, h.run_duration as LastStatusDuration,
case h.run_status 
when 0 then 'Failed' 
when 1 then 'Successful' 
when 3 then 'Cancelled' 
when 4 then 'In Progress' 
end as JobStatus
from msdb..sysJobHistory h, msdb..sysJobs j
where j.job_id = h.job_id
and h.step_id = 1
and h.run_date = 
(select max(hi.run_date) from msdb..sysJobHistory hi where h.job_id = hi.job_id)
and h.run_time =
(select max(hj.run_time) from msdb..sysJobHistory hj where h.job_id = hj.job_id)
order by 1
登入後複製
select distinct cat.name as "Category", j.Name as "Job Name", j.description as "Job Description",
 h.run_date as LastStatusDate, h.run_time as LastStatusTime, h.run_duration as LastStatusDuration,
case h.run_status 
when 0 then 'Failed' 
when 1 then 'Successful' 
when 3 then 'Cancelled' 
when 4 then 'In Progress' 
end as JobStatus
from msdb..sysJobHistory h, msdb..sysJobs j, msdb..syscategories cat
where j.job_id = h.job_id and
j.category_id = cat.category_id
and h.step_id = 1
and h.run_date = 
(select max(hi.run_date) from msdb..sysJobHistory hi where h.job_id = hi.job_id)
and h.run_time =
(select max(hj.run_time) from msdb..sysJobHistory hj where h.job_id = hj.job_id)

order by 1,3
登入後複製
Select 
        [Job Name] = j.name 
      , [Job Description] = j.description
      , [LastRunDate] = h.run_date 
	  , [LastRunTime] = h.run_time
      , [JobStatus] = Case h.run_status
          When 0 Then 'Failed'
          When 1 Then 'Successful'
          When 3 Then 'Cancelled'
          When 4 Then 'In Progress'
        End
		,[OrderOfRun] = Rank() Over(Partition By j.job_id Order By h.run_date Desc,h.run_time Desc)
    From
        msdb.dbo.sysjobhistory h
      Left join msdb.dbo.sysjobs j On j.job_id = h.job_id
    Where h.step_id=0 --only look @ Job Outcome step
Order By [Job Name] desc,Rank() Over(Partition By j.job_id Order By h.run_date Desc,h.run_time Desc) Asc
登入後複製
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板