Provides information about the jobs for servers in the multiserver administration domain.
sp_help_jobhistory [[@job_id =] job_id]
[, [@job_name =] 'job_name']
[, [@step_id =] step_id]
[, [@sql_message_id =] sql_message_id]
[, [@sql_severity =] sql_severity]
[, [@start_run_date =] start_run_date]
[, [@end_run_date =] end_run_date]
[, [@start_run_time =] start_run_time]
[, [@end_run_time =] end_run_time]
[, [@minimum_run_duration =] minimum_run_duration]
[, [@run_status =] run_status]
[, [@minimum_retries =] minimum_retries]
[, [@oldest_first =] oldest_first]
[, [@server =] 'server']
[, [@mode =] 'mode']
Value | Description |
---|---|
0 | Failed |
1 | Succeeded |
2 | Retry (step only) |
3 | Canceled |
4 | In-progress message |
5 | Unknown |
0 (success) or 1 (failure)
The actual column list depends on the value of mode. The most comprehensive set of columns is shown below and is returned when mode is FULL.
Column name | Data type | Description |
---|---|---|
instance_id | int | History entry identification number. |
job_id | uniqueidentifier | Job identification number. |
job_name | sysname | Job name. |
step_id | int | Step identification number (will be 0 for a job history). |
step_name | sysname | Step name (will be NULL for a job history). |
sql_message_id | int | For Transact-SQL step, the most recent Transact-SQL error number encountered while running the command. |
sql_severity | int | For a Transact-SQL step, the highest Transact-SQL error severity encountered while running the command. |
message | nvarchar(1024) | Job or step history message. |
run_status | int | Outcome of the job or step. |
run_date | int | Date the job or step began executing. |
run_time | int | Time the job or step began executing. |
run_duration | int | Amount of time (in seconds) the job or step took to run to completion. |
operator_emailed | nvarchar(20) | Operator who was e-mailed regarding this job (is NULL for step history). |
operator_netsent | nvarchar(20) | Operator who was sent a network message regarding this job (is NULL for step history). |
operator_paged | nvarchar(20) | Operator who was paged regarding this job (is NULL for step history). |
retries_attempted | int | Number of times the step was retried (always 0 for a job history). |
server | nvarchar(30) | Server the step or job executes on. Is always (local). |
sp_help_jobhistory returns a report with the history of the specified scheduled jobs. If no parameters are specified, the report contains the history for all scheduled jobs.
Permissions to execute this procedure default to the sysadmin fixed server role or the db-owner fixed database role, who can grant permissions to other users.
This example prints all columns and all job information for any failed jobs and failed job steps with an error message of 50100 (a user-defined error message), a severity of 20, and a start date of June 1, 1998, on the LONDON2 server.
USE msdb
EXEC sp_help_jobhistory NULL, NULL, NULL, 50100, 20, 19980601, NULL,
NULL, NULL, NULL, 0, NULL, 1, 'LONDON2', FULL
sp_purge_jobhistory | System Stored Procedures |