Lists information about the runtime state of SQL Server Agent jobs.
Returns the following result set:
Agent session identification number.
Identifier for the job.
Name of the job.
When that the job was requested to run.
The source of the request to run the job. One of:
1 = Run on a schedule
2 = Run in response to an alert
3 = Run on startup
4 = Run by user
6 = Run on CPU idle schedule
When the request was queued. NULL if the job was run directly.
When the job was assigned to a runnable thread.
The step ID of the most recently run job step.
The time that the most recently run job step started to run.
The time that the job stopped running.
When the job is next scheduled to run.
Identifier for the job history in the job history table.
Message produced during the last run of the job.
Status returned from the last run of the job:
0 = Error failed
1 = Succeeded
3 = Canceled
5 = Status unknown
ID number of the operator notified via email at completion of the job.
ID number of the operator notified via net send at completion of the job.
ID number of the operator notified via pager at completion of the job.
This procedure provides a snapshot of the current state of the jobs. The results returned represent information at the time that the request is processed.
SQL Server Agent creates a session id each time that the Agent service starts. The session id is stored in the table msdb.dbo.syssessions.
When no session_id is provided, lists information about the most recent session.
When no job_name or job_id is provided, lists information for all jobs.
By default, members of the sysadmin fixed server role can run this stored procedure. Other users must be granted one of the following SQL Server Agent fixed database roles in the msdb database:
For details about the permissions of these roles, see SQL Server Agent Fixed Database Roles.
Only members of sysadmin can view the activity for jobs owned by other users.
The following example lists activity for all jobs that the current user has permission to view.
USE msdb ; GO EXEC dbo.sp_help_jobactivity ; GO