sp_help_jobstep (Transact-SQL)

 

Returns information for the steps in a job used by SQL Server Agent service to perform automated activities.

Applies to: SQL Server (SQL Server 2008 through current version).

Topic link icon Transact-SQL Syntax Conventions

  
sp_help_jobstep { [ @job_id = ] 'job_id' | [ @job_name = ] 'job_name' }  
     [ , [ @step_id = ] step_id ]   
     [ , [ @step_name = ] 'step_name' ]   
     [ , [ @suffix = ] suffix ]   

[ @job_id =] 'job_id'
The job identification number for which to return job information. job_id is uniqueidentifier, with a default of NULL.

[ @job_name =] 'job_name'
The name of the job. job_name is sysname, with a default NULL.

System_CAPS_ICON_note.jpg Note


Either job_id or job_name must be specified, but both cannot be specified.

[ @step_id =] step_id
The identification number of the step in the job. If not included, all steps in the job are included. step_id is int, with a default of NULL.

[ @step_name =] 'step_name'
The name of the step in the job. step_name is sysname, with a default of NULL.

[ @suffix =] suffix
A flag indicating whether a text description is appended to the flags column in the output. suffixis bit, with the default of 0. If suffix is 1, a description is appended.

0 (success) or 1 (failure)

Column nameData typeDescription
step_idintUnique identifier for the step.
step_namesysnameName of the step in the job.
subsystemnvarchar(40)Subsystem in which to execute the step command.
commandnvarchar(max)Command executed in the step.
flagsintA bitmask of values that control step behavior.
cmdexec_success_codeintFor a CmdExec step, this is the process exit code of a successful command.
on_success_actiontinyintAction to take if the step succeeds:

 1 = Quit the job reporting success.

 2 = Quit the job reporting failure.

 3 = Go to the next step.

 4 = Go to step.
on_success_step_idintIf on_success_action is 4, this indicates the next step to execute.
on_fail_actiontinyintWhat to do if the step fails. Values are same as on_success_action.
on_fail_step_idintIf on_fail_action is 4, this indicates the next step to execute.
serversysnameReserved.
database_namesysnameFor a Transact-SQL step, this is the database in which the command executes.
database_user_namesysnameFor a Transact-SQL step, this is the database user context in which the command executes.
retry_attemptsintMaximum number of times the command should be retried (if it is unsuccessful).
retry_intervalintInterval (in minutes) for any retry attempts.
os_run_priorityintReserved.
output_file_namenvarchar(200)File to which command output should be written (Transact-SQL, CmdExec, and PowerShell steps only).
last_run_outcomeintOutcome of the step the last time it ran:

 0 = Failed

 1 = Succeeded

 2 = Retry

 3 = Canceled

 5 = Unknown
last_run_durationintDuration (in seconds) of the step the last time it ran.
last_run_retriesintNumber of times the command was retried the last time the step ran.
last_run_dateintDate the step last started execution.
last_run_timeintTime the step last started execution.
proxy_idintProxy for the job step.

sp_help_jobstep is in the msdb database.

By default, members of the sysadmin fixed server role can execute this stored procedure. Other users must be granted one of the following SQL Server Agent fixed database roles in the msdb database:

  • SQLAgentUserRole

  • SQLAgentReaderRole

  • SQLAgentOperatorRole

For details about the permissions of these roles, see SQL Server Agent Fixed Database Roles.

Members of SQLAgentUserRole can only view job steps for jobs that they own.

A. Return information for all steps in a specific job

The following example returns all the job steps for the job named Weekly Sales Data Backup.

USE msdb ;  
GO  
  
EXEC dbo.sp_help_jobstep  
    @job_name = N'Weekly Sales Data Backup' ;  
GO  

B. Return information about a specific job step

The following example returns information about the first job step for the job named Weekly Sales Data Backup.

USE msdb ;  
GO  
  
EXEC dbo.sp_help_jobstep  
    @job_name = N'Weekly Sales Data Backup',  
    @step_id = 1 ;  
GO  

sp_add_jobstep (Transact-SQL)
sp_delete_jobstep (Transact-SQL)
sp_help_job (Transact-SQL)
sp_update_jobstep (Transact-SQL)
System Stored Procedures (Transact-SQL)

Community Additions

ADD
Show: