Situatie
Mai jos este o procedura ce listeaza pe serverul pe care este rulata, toate joburile ce nu au mai folosite de mai mult de 12 luni.
Solutie
create procedure ListUnusedJobs_prc
as
SELECT
@@SERVERNAME ServerName,
J.name,
J.[enabled],
JA.LastRun,
JA.NextRun,
JV.[description],
JC.name JobCategory
FROM msdb.dbo.sysjobs J
JOIN msdb.dbo.sysjobs_view JV ON J.job_id = JV.job_id
JOIN
(
SELECT job_id, MAX(last_executed_step_date) LastRun, MAX(next_scheduled_run_date) NextRun
FROM msdb.dbo.sysjobactivity
GROUP BY job_id
) JA ON J.job_id = JA.job_id
JOIN msdb.dbo.syscategories JC ON J.category_id = JC.category_id
WHERE DATEDIFF(m, ISNULL(LastRun, ‘1900-01-01’), GETDATE()) > 12 OR NextRun < GETDATE()
Leave A Comment?