Adding SQL Server Agent Job Frequency to output

  • I currently have a ps script that provides me with the SQL Server Agent job information from a failed/successful job perspective. Currently the data that I am returning contains, Job Name, Job Last Run, Job Last Run Date, Job Next Run Date, Job Enabled, and the Job Schedule. The Job Schedule part is what I am having trouble with. I would like to return the job frequency such as Daily, Weekly and etc. I am not quite sure how to do this. Anybody have any pointers or know of a good site that may have this information?

  • What have you got so far? Have you lookied into http://msdn.microsoft.com/en-us/library/ms219082.aspx ??

    __________________________
    Allzu viel ist ungesund...

  • Below query will give Job Frequency type.

    SELECT

    [sJOB].[job_id] AS [JobID]

    , [sJOB].[name] AS [JobName]

    , [sDBP].[name] AS [JobOwner]

    , [sCAT].[name] AS [JobCategory]

    , [sJOB].[description] AS [JobDescription]

    , CASE [sJOB].[enabled]

    WHEN 1 THEN 'Yes'

    WHEN 0 THEN 'No'

    END AS [IsEnabled]

    , CASE [sSCH].freq_type

    WHEN 4 THEN 'Daily'

    WHEN 8 THEN 'Weekly'

    WHEN 16 THEN 'Monthly'

    END AS [JobFrequency]

    , [sJOB].[date_created] AS [JobCreatedOn]

    , [sJOB].[date_modified] AS [JobLastModifiedOn]

    , [sSVR].[name] AS [OriginatingServerName]

    , [sJSTP].[step_id] AS [JobStartStepNo]

    , [sJSTP].[step_name] AS [JobStartStepName]

    , CASE

    WHEN [sSCH].[schedule_uid] IS NULL THEN 'No'

    ELSE 'Yes'

    END AS [IsScheduled]

    , [sSCH].[schedule_uid] AS [JobScheduleID]

    , [sSCH].[name] AS [JobScheduleName]

    , CASE [sJOB].[delete_level]

    WHEN 0 THEN 'Never'

    WHEN 1 THEN 'On Success'

    WHEN 2 THEN 'On Failure'

    WHEN 3 THEN 'On Completion'

    END AS [JobDeletionCriterion]

    FROM

    [msdb].[dbo].[sysjobs] AS [sJOB]

    LEFT JOIN [msdb].[sys].[servers] AS [sSVR]

    ON [sJOB].[originating_server_id] = [sSVR].[server_id]

    LEFT JOIN [msdb].[dbo].[syscategories] AS [sCAT]

    ON [sJOB].[category_id] = [sCAT].[category_id]

    LEFT JOIN [msdb].[dbo].[sysjobsteps] AS [sJSTP]

    ON [sJOB].[job_id] = [sJSTP].[job_id]

    AND [sJOB].[start_step_id] = [sJSTP].[step_id]

    LEFT JOIN [msdb].[sys].[database_principals] AS [sDBP]

    ON [sJOB].[owner_sid] = [sDBP].[sid]

    LEFT JOIN [msdb].[dbo].[sysjobschedules] AS [sJOBSCH]

    ON [sJOB].[job_id] = [sJOBSCH].[job_id]

    LEFT JOIN [msdb].[dbo].[sysschedules] AS [sSCH]

    ON [sJOBSCH].[schedule_id] = [sSCH].[schedule_id]

    ORDER BY [JobName]

  • Thank you both for your time. I will look through this information and let you know how it goes.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply