Sometime you might want to get a list of SQL Server Agent Jobs and their schedules on your current SQL server instance. You could manually open each and every Agent job through SSMS and note down the details you required, but it might take long time depend on number of jobs on the server. But below script will help you to get detailed list of SQL Server Agent Jobs at once.
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 |
SELECT DISTINCT a.name AS [SQL Agent Job Name], CASE WHEN a.enabled = 0 THEN 'Disabled' WHEN a.enabled = 1 THEN 'Enabled' end AS [Job Status], a.date_Created AS [Job Created Date], b.name AS [Schedule Name], CASE WHEN b.freq_type = 1 THEN 'Once' WHEN b.freq_type = 4 THEN 'Daily' WHEN b.freq_type = 8 THEN 'Weekly' WHEN b.freq_type = 16 THEN 'Monthly' WHEN b.freq_type = 32 THEN 'Monthly, relative to interval' WHEN b.freq_type = 64 THEN 'Runs when the SQL Server Agent service starts' WHEN b.freq_type = 128 THEN 'Runs when the computer is idle' END AS [Job Running Frequency], CASE WHEN b.freq_subday_type = 1 THEN 'At the specified time' WHEN b.freq_subday_type = 2 THEN 'Seconds' WHEN b.freq_subday_type = 4 THEN 'Minutes' WHEN b.freq_subday_type = 8 THEN 'Hours' END as [Interval], b.date_created as [Schedule created date], CAST(CAST(b.active_start_date AS VARCHAR(10)) as date) AS [Execution begin], CAST(CAST(b.active_end_date AS VARCHAR(10))as date) AS [Execution stop] FROM msdb.dbo.sysjobs a LEFT JOIN msdb.dbo.sysJobschedules c ON a.job_id = c.job_id LEFT JOIN msdb.dbo.SysSchedules b on b.Schedule_id=c.Schedule_id |
Leave a Comment