Skip to content

Instantly share code, notes, and snippets.

@petesql
Created February 15, 2025 22:16
Show Gist options
  • Save petesql/372bc74ad293736f01caf5748b9cbb71 to your computer and use it in GitHub Desktop.
Save petesql/372bc74ad293736f01caf5748b9cbb71 to your computer and use it in GitHub Desktop.
List SQL Agent Jobs Script
-- List all SQL Agent jobs with schedule details
SELECT
j.job_id,
j.name,
j.description,
j.enabled,
j.date_created,
j.date_modified,
s.step_id,
s.step_name,
s.database_name,
s.subsystem,
s.command,
s.on_success_action,
s.on_fail_action,
s.retry_attempts,
s.retry_interval,
h.run_date,
h.run_time,
h.run_duration,
h.run_status,
sch.name AS schedule_name,
sch.freq_type,
sch.freq_interval,
sch.active_start_time
FROM msdb.dbo.sysjobs j
LEFT JOIN msdb.dbo.sysjobsteps s ON j.job_id = s.job_id
LEFT JOIN msdb.dbo.sysjobhistory h
ON j.job_id = h.job_id
AND h.instance_id = (SELECT MAX(instance_id) FROM msdb.dbo.sysjobhistory WHERE job_id = j.job_id)
LEFT JOIN msdb.dbo.sysjobschedules js ON j.job_id = js.job_id
LEFT JOIN msdb.dbo.sysschedules sch ON js.schedule_id = sch.schedule_id
ORDER BY j.name, s.step_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment