|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Saturday, January 19, 2013 6:20 PM
Points: 120,
Visits: 299
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 11:22 AM
Points: 1,268,
Visits: 1,477
|
|
Thanks, I like it!
I did make a couple of minor changes. Our server names are >10 characters and I like to see the run date and run time in descending order.
SET DATEFORMAT dmy SELECT convert(varchar(20),his.server) as Server, -- Increased to 20 characters convert(varchar(30),job.name) AS job_name, CASE his.run_status WHEN 0 THEN 'Failed' WHEN 1 THEN 'Succeeded' ELSE '???' END as run_status, convert(varchar(4),run_duration/10000) + ':' + convert(varchar(4),run_duration/100%100) + ':' + convert(varchar(4),run_duration%100) as run_duration, convert(datetime, convert(varchar(10),run_date%100) + '/' + convert(varchar(10),run_date/100%100) + '/' + convert(varchar(10),run_date/10000) + ' ' + convert(varchar(4),run_time/10000) + ':' + convert(varchar(4),run_time/100%100) + ':' + convert(varchar(4),run_time%100)) as start_date, datediff(mi, getdate()-1, convert(datetime, convert(varchar(10),run_date%100) + '/' + convert(varchar(10),run_date/100%100) + '/' + convert(varchar(10),run_date/10000) + ' ' + convert(varchar(4),run_time/10000) + ':' + convert(varchar(4),run_time/100%100) + ':' + convert(varchar(4),run_time%100))) as LeadingMinutes, isnull(nullif(convert(int,(run_duration/10000 * 60) + (run_duration/100%100) + (ceiling(run_duration%100/60.0))),0),1) as DurationMinutes, REPLICATE(' ', datediff(mi, getdate()-1, convert(datetime, convert(varchar(10),run_date%100) + '/' + convert(varchar(10),run_date/100%100) + '/' + convert(varchar(10),run_date/10000) + ' ' + convert(varchar(4),run_time/10000) + ':' + convert(varchar(4),run_time/100%100) + ':' + convert(varchar(4),run_time%100)))) + REPLICATE('x', isnull(nullif(convert(int,(run_duration/10000 * 60) + (run_duration/100%100) + (ceiling(run_duration%100/60.0))),0),1)) as DurationTimeline, his.message FROM msdb.dbo.sysjobhistory his INNER JOIN msdb.dbo.sysjobs job ON his.job_id = job.job_id WHERE convert(datetime, convert(varchar(10),run_date%100) + '/' + convert(varchar(10),run_date/100%100) + '/' + convert(varchar(10),run_date/10000) + ' ' + convert(varchar(4),run_time/10000) + ':' + convert(varchar(4),run_time/100%100) + ':' + convert(varchar(4),run_time%100)) between getdate()-1 and getdate() and step_id = 0 ORDER BY his.server, his.run_date DESC, -- Added DESC his.run_time DESC, -- Added DESC job.name
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Today @ 5:32 PM
Points: 306,
Visits: 1,013
|
|
Nicely done! I like the graph too.
I was looking at the graph and thought shouldn't it reset back to left side of the "Duration Timeline" once the the next day's jobs are executed? Currently it looks like (from the graph) that the times of the jobs are changing.
Just a thought.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, April 08, 2013 5:14 PM
Points: 16,
Visits: 556
|
|
| I'm a newbie. can you explain a little more about leading minutes and duration timeline column? I don't understand. What spaces are you talking about? Please help me to understand.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Saturday, January 19, 2013 6:20 PM
Points: 120,
Visits: 299
|
|
Hi amc. It works like a bar chart. For every minute a job is running, an 'X' is printed. For every minute it is not running, a space is printed. You can compare the lines to see when jobs are running at the same time. So, if you have one row returned where the 'X's line up vertically with the lines above or below it, then it means the jobs were running concurrently.
Hope that helps,
Martin
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, April 08, 2013 5:14 PM
Points: 16,
Visits: 556
|
|
Oh--Ok, I got it now. thank you! Becasue I really like this query. Uh, one more thing...explain LeadingMinutes, please.
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Today @ 3:58 PM
Points: 279,
Visits: 1,025
|
|
Nice Script ... I would like to know whats mean of XX in result. i can not see last week's jobs result . like today tue morning i am running this script it showing me result on 2011-01-09 and 2011-01-10 what if i want to see results before this duration? Thanks
Aim to inspire rather than to teach. SQL Server DBA
|
|
|
|