Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Script Library
 List Scheduled Jobs

Author  Topic 

nguyen
Starting Member

8 Posts

Posted - 2004-03-30 : 13:14:56
/*
DISPLAYS scheduled jobs ordered by date and time.
I couldn't find a SP to do this so I borrowed some code from
msdb.dbo.sp_get_composite_job_info

Louis Nguyen
*/

CREATE PROCEDURE UtilityJobsSchedule
AS
SET ANSI_WARNINGS OFF
set nocount on
set transaction isolation level read uncommitted

create table #T(
job_id uniqueidentifier,
a2 varchar(100),
a3 varchar(100),
nextrundate varchar(100),
nextruntime varchar(100),
a6 varchar(100),
a7 varchar(100),
a8 varchar(100),
a9 varchar(100),
a10 varchar(100),
a11 varchar(100),
a12 varchar(100),
a13 varchar(100)
)

DECLARE @is_sysadmin INT
DECLARE @job_owner sysname
SELECT @is_sysadmin = ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0)
SELECT @job_owner = SUSER_SNAME()
INSERT INTO #T
EXECUTE master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @job_owner

SELECT sjv.name,fj.nextrundate,
nextruntime=case when len(fj.nextruntime) > 3 then substring(fj.nextruntime,1,len(fj.nextruntime)-2) else fj.nextruntime end
FROM #T fj
JOIN msdb.dbo.sysjobs_view sjv ON (fj.job_id = sjv.job_id and sjv.enabled=1)
ORDER BY fj.nextrundate,
cast(case when len(fj.nextruntime) > 3 then substring(fj.nextruntime,1,len(fj.nextruntime)-2) else fj.nextruntime end as int)

GO
   

- Advertisement -