SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Job History Display
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

amccarthy
Starting Member

3 Posts

Posted - 06/25/2012 :  11:24:43  Show Profile  Reply with Quote
Hi all,

I am attempting to create a dashboard in srss to display whether jobs have succeeded or failed. One of the business requirements is having an initial page that displays a date, and whether or not any jobs failed for that day. The problem I am running into is that there are multiple jobs for each day, and some will fail and some will succeed. This leads to multiple rows for the same date, one saying there was a failure and one saying there was a success. How would I get a query to return a series of dates and whether or not the entire batch of jobs for the day succeeded or if there was a failure?

yosiasz
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 06/25/2012 :  11:51:01  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
is there any reason why are you not using the report that comes with SQL? otherwise you can query the sys tables. here is one I got from google schmoogle


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]
    , [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]


<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

amccarthy
Starting Member

3 Posts

Posted - 06/25/2012 :  12:02:40  Show Profile  Reply with Quote
yosiasz,

Thanks for your response.

I'm attempting to create a custom job history report. On my dashboard, I've already created a page that displays information about a particular job (Start_date, end_date, duration, success/failure), and a page that displays all the job failures in a given period.

As per my business requirements, I must create a home page that merely displays a running date (about the past three days or so) and a single column that informs the user whether or not any jobs have failed for that date.

What I have tried is using this:
SELECT
distinct CONVERT(CHAR(10), CAST(STR(run_date,8, 0) AS dateTIME), 111) as T1_Dt,
Completion_Status_Success =
(case when run_status=1
then 'success'
else 'fail'
end
)
FROM dbo.sysjobhistory
order by
T1_Dt desc

However, this displays:
Date||CompletionStatus
2012/06/25||fail
2012/06/25||success
2012/06/24||fail
2012/06/24||success
etc

What I would like the display to do is if any jobs ran on a particular date fail, display completion status as fail. BUT if no jobs failed on a particular date, then have it display success.

Hopefully this clarifies my question.
Go to Top of Page

yosiasz
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 06/25/2012 :  12:28:35  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
sysjobhistory? is this sql 2000?

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

amccarthy
Starting Member

3 Posts

Posted - 06/25/2012 :  13:04:10  Show Profile  Reply with Quote
I'm running SQL Server 2008 R2
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000