Skip to content

Instantly share code, notes, and snippets.

@Otterpohl
Created May 13, 2022 15:41
Show Gist options
  • Save Otterpohl/955c658c08ef1543c7d044030327d220 to your computer and use it in GitHub Desktop.
Save Otterpohl/955c658c08ef1543c7d044030327d220 to your computer and use it in GitHub Desktop.
Gets the schedules for all agent jobs
select CASE (ss.freq_subday_type)
WHEN 1 then left(stuff((stuff((replicate('0', 6 - len(ss.active_start_time)))+ convert(varchar(6),ss.active_start_time),3,0,':')),6,0,':'),8)
WHEN 2 then 'Every ' + convert(varchar(10),ss.freq_subday_interval) + ' seconds'
WHEN 4 then 'Every ' + convert(varchar(10),ss.freq_subday_interval) + ' minutes'
WHEN 8 then 'Every ' + convert(varchar(10),ss.freq_subday_interval) + ' hours'
ELSE '??'
END AS [Time],
s.Name
from msdb.dbo.sysjobs AS s
left join msdb.dbo.sysjobschedules AS sj on S.job_id = SJ.job_id
left join msdb.dbo.sysschedules AS ss on SS.schedule_id = SJ.schedule_id
order by S.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment