Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Convert Job Duration Format Expand / Collapse
Author
Message
Posted Thursday, July 26, 2012 7:37 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Sunday, July 27, 2014 6:10 AM
Points: 4,179, Visits: 4,260
The following script returns the run_duration as for example:

45028
43520
3007
40529
2509

I want 45028 to be formatted as 4:50:28 hh:mm:ss.

USE MSDB
GO

SELECT j.name AS JobName,h.step_name AS StepName,
CONVERT(CHAR(10), CAST(STR(h.run_date,8, 0) AS dateTIME), 111) AS RunDate,
STUFF(STUFF(RIGHT('000000' + CAST ( h.run_time AS VARCHAR(6 ) ) ,6),5,0,':'),3,0,':') AS RunTime,
h.run_duration AS StepDuration,
case h.run_status when 0 then 'failed'
when 1 then 'Succeded'
when 2 then 'Retry'
when 3 then 'Cancelled'
when 4 then 'In Progress'
end as ExecutionStatus,
h.message MessageGenerated
FROM sysjobhistory AS h
INNER JOIN sysjobs AS j
ON j.job_id = h.job_id
WHERE j.Name = 'AS400_Download'
AND h.step_name = '(Job outcome)'
AND h.run_duration > '1500'
ORDER BY j.name, h.run_date DESC , h.run_duration DESC--h.run_time DESC

Any help would be greatly appreciated.


For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Post #1336192
Posted Friday, July 27, 2012 3:34 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 7:36 AM
Points: 23,083, Visits: 31,624
You do know that you had everything there you needed to do this, right?

here is my code, with your WHERE clause commented:


SELECT
j.name AS JobName,
h.step_name AS StepName,
CONVERT(CHAR(10), CAST(STR(h.run_date,8, 0) AS datetime), 111) AS RunDate,
STUFF(STUFF(RIGHT('000000' + CAST (h.run_time AS VARCHAR(6)),6),5,0,':'),3,0,':') AS RunTime,
STUFF(STUFF(RIGHT('000000' + CAST (h.run_duration AS VARCHAR(6)),6),5,0,':'),3,0,':') AS StepDuration,
--h.run_duration AS StepDuration,
case h.run_status when 0 then 'failed'
when 1 then 'Succeded'
when 2 then 'Retry'
when 3 then 'Cancelled'
when 4 then 'In Progress'
end as ExecutionStatus,
h.message MessageGenerated
FROM
sysjobhistory AS h
INNER JOIN sysjobs AS j
ON j.job_id = h.job_id
--WHERE
-- j.Name = 'AS400_Download'
-- AND h.step_name = '(Job outcome)'
-- AND h.run_duration > '1500'
ORDER BY
j.name,
h.run_date DESC,
h.run_duration DESC--h.run_time DESC





Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1336349
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse