-
Notifications
You must be signed in to change notification settings - Fork 5
/
SQL_Server_Jobs_List_Schedule.sql
44 lines (43 loc) · 1.85 KB
/
SQL_Server_Jobs_List_Schedule.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* Thank you to Daniel Messer. This
query pulls a list of SQL jobs set up in SQL Server along with all the information connected to them
like frequency, start time, end time, intervals and so on.
It’s particularly useful if you need to back up, clone, or reset a database system.*/
SELECT
j.name AS [Job Name],
s.name AS [Schedule Name,
s.enabled AS [ScheduleEnabled],
s.freq_type AS [Frequency Type],
s.freq_interval AS [Frequency Interval],
s.freq_subday_type AS [Subday Type],
s.freq_subday_interval AS [Subday Interval],
s.freq_relative_interval AS [Relative Interval],
s.freq_recurrence_factor AS [Recurrence Factor],
s.active_start_date AS [Active Start Date],
s.active_end_date AS [Active End Date],
RIGHT('0' + CAST(s.active_start_time / 10000 AS VARCHAR(2)), 2) + ':' +
RIGHT('0' + CAST((s.active_start_time / 100) % 100 AS VARCHAR(2)), 2) + ':' +
RIGHT('0' + CAST(s.active_start_time % 100 AS VARCHAR(2)), 2) AS ActiveStartTime,
RIGHT('0' + CAST(s.active_end_time / 10000 AS VARCHAR(2)), 2) + ':' +
RIGHT('0' + CAST((s.active_end_time / 100) % 100 AS VARCHAR(2)), 2) + ':' +
RIGHT('0' + CAST(s.active_end_time % 100 AS VARCHAR(2)), 2) AS ActiveEndTime,
CASE
WHEN s.freq_type = 1 THEN 'One Time'
WHEN s.freq_type = 4 THEN 'Daily'
WHEN s.freq_type = 8 THEN 'Weekly'
WHEN s.freq_type = 16 THEN 'Monthly'
WHEN s.freq_type = 32 THEN 'Monthly, relative to frequency'
WHEN s.freq_type = 64 THEN 'When SQL Server Agent starts'
WHEN s.freq_type = 128 THEN 'When the computer is idle'
ELSE 'Unknown'
END AS FrequencyDescription
FROM
msdb.dbo.sysjobs j
INNER JOIN
msdb.dbo.sysjobschedules js
ON (j.job_id = js.job_id)
INNER JOIN
msdb.dbo.sysschedules s
ON (js.schedule_id = s.schedule_id)
ORDER BY
j.name,
s.name;