select j.job_id, j.name as JobName, j.[enabled] as JobEnabled,
js.schedule_id,
( CASE s.freq_type
WHEN 1 THEN 'One time only'
WHEN 4 THEN 'Daily'
WHEN 8 THEN 'Weekly'
WHEN 16 THEN 'Monthly'
WHEN 32 THEN 'Monthly relative'
WHEN 64 THEN 'When SQLServer Agent starts'
WHEN 128 THEN 'When the computer is idle'
ELSE ''
END
) Frequently,
( CASE len(s.active_start_time)
WHEN 1 THEN cast('00:00:0' + cast(s.active_start_time as char) as char (8))
WHEN 2 THEN cast('00:00:' + cast(s.active_start_time as char) as char (8))
WHEN 3 THEN cast('00:0' + Left(right(s.active_start_time ,3),1) + ':' + right(s.active_start_time,2) as char (8))
WHEN 4 THEN cast('00:' + Left(right(s.active_start_time ,4),2) + ':' + right(s.active_start_time,2) as char (8))
WHEN 5 THEN cast('0' + Left(right(s.active_start_time ,5),1) + ':' + Left(right(s.active_start_time ,4),2) +':' + right(s.active_start_time,2) as char (8))
WHEN 6 THEN cast(Left(right(s.active_ start_time,6),2) + ':' + Left(right(s.active_start_time ,4),2) + ':' + right(s.active_start_time,2) as char (8))
END
) as RunTime
from msdb.dbo.sysjobs j
join msdb.dbo.sysjobschedules js on j.job_id = js.job_id
join msdb.dbo.sysschedules s on js.schedule_id = s.schedule_id
where s.[enabled] = 1
and s.freq_type between 4 and 32
order by s.freq_type, s.active_start_time
This query return the scheduling's of jobs in the server.
Jobs without scheduling won't be return (unless you change the query to LEFT JOINs) – in order to get the scheduling mapping in the server.
No comments:
Post a Comment