sp_help_jobcount (Transact-SQL)

 

THIS TOPIC APPLIES TO:yesSQL Server (starting with 2008)noAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse

Provides the number of jobs that a schedule is attached to.

Topic link icon Transact-SQL Syntax Conventions

  
sp_help_jobcount   
     [ @schedule_name = ] 'schedule_name' ,  
     [ @schedule_id = ] schedule_id   

[ @schedule_id= ] schedule_id
The identifier of the schedule to list. schedule_id is int, with no default. Either schedule_id or schedule_name may be specified.

[ @schedule_name= ] 'schedule_name'
The name of the schedule to list. schedule_name is sysname, with no default. Either schedule_id or schedule_name may be specified.

0 (success) or 1 (failure)

Returns the following result set:

Column nameData typeDescription
JobCountintNumber of jobs for the specified schedule.

This procedure lists the number of jobs attached to the specified schedule.

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.

Only members of sysadmin can view counts for jobs that are owned by others.

The following example lists the number of jobs attached to the NightlyJobs schedule.

USE msdb ;  
GO  
  
EXEC sp_help_jobcount  
    @schedule_name = N'NightlyJobs' ;  
GO  

SQL Server Agent Stored Procedures (Transact-SQL)
sp_add_schedule (Transact-SQL)
sp_attach_schedule (Transact-SQL)
sp_delete_schedule (Transact-SQL)
sp_detach_schedule (Transact-SQL)

Community Additions

ADD
Show: