I need to write a query that will look at the SQL job run history and return the amount of times each job has failed or succeeded. To be more specific a DTSX package will go out to group of servers and populate a table with all those servers job history. Then a query which will essentially be the report, will aggregate that local table. I am very close to getting what I want but having trouble summing the run_status column to count the total times the job succeeded and the times it failed. I basically want something that returns what I have below with the addition of failed and success count columns. Thanks for any help provided…
;WITH CTE_MostRecentJobRun AS ( -- For each job get the most recent run (this will be the one where Rnk=1) SELECT job_id, run_status, run_date, run_time, RANK() OVER (PARTITION BY job_id ORDER BY run_date DESC,run_time DESC) AS Rnk, run_duration --STUFF(STUFF(STUFF(RIGHT(REPLICATE('0', 8) + CAST(run_duration as varchar(8)), 8), 3, 0, ':'), 6, 0, ':'), 9, 0, ':') 'Duration(DD:HH:MM:SS)' FROM msdb..sysjobhistory WHERE step_id=0 ) SELECT sj.name AS [Job Name], CASE sj.notify_level_email WHEN 0 THEN 'Never' WHEN 1 THEN 'When Job Succeeds' WHEN 2 THEN 'When Job Fails' WHEN 3 THEN 'When Finshed' END AS 'Email Notification', CONVERT(VARCHAR,DATEADD(S,(run_time/10000)*60*60 /* hours */ +((run_time - (run_time/10000) * 10000)/100) * 60 /* mins */ + (run_time - (run_time/100) * 100) /* secs */, CONVERT(DATETIME,RTRIM(run_date),113)),100) AS [Last Ran], CASE run_status WHEN 0 THEN 'Failed' WHEN 1 THEN 'Succeeded' WHEN 2 THEN 'Retry' ELSE 'Canceled' END AS run_status, CASE WHEN enabled=1 THEN 'Enabled' ELSE 'Disabled' END [Job Status], STUFF(STUFF(STUFF(RIGHT(REPLICATE('0', 8) + CAST(run_duration as varchar(8)), 8), 3, 0, ':'), 6, 0, ':'), 9, 0, ':') 'Duration(DD:HH:MM:SS)' FROM CTE_MostRecentJobRun MRJR JOIN msdb..sysjobs SJ ON MRJR.job_id=sj.job_id WHERE Rnk=1 ORDER BY name
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!