我需要一个应用程序来监控SQL Server Jobs.For例如:我有CPU使用率图形,时间刻度在14:00:200和14:20:000之间156.应该看到编号的工作。我想做点什么像这样。我是新手程序员。这有可能吗?抱歉我的英语不好
答案 0 :(得分:2)
您可以使用
SELECT
ja.job_id,
j.name AS job_name,
ja.start_execution_date,
ISNULL(last_executed_step_id,0)+1 AS current_executed_step_id,
Js.step_name
FROM msdb.dbo.sysjobactivity ja
LEFT JOIN msdb.dbo.sysjobhistory jh
ON ja.job_history_id = jh.instance_id
JOIN msdb.dbo.sysjobs j
ON ja.job_id = j.job_id
JOIN msdb.dbo.sysjobsteps js
ON ja.job_id = js.job_id
AND ISNULL(ja.last_executed_step_id,0)+1 = js.step_id
WHERE ja.session_id = (SELECT TOP 1 session_id FROM msdb.dbo.syssessions ORDER BY agent_start_date DESC)
AND start_execution_date is not null
AND stop_execution_date is null;
来源:http://sqlstudies.com/2013/09/05/a-t-sql-query-to-get-current-job-activity/