Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SysJobHistory

Author  Topic 

pareshmotiwala
Constraint Violating Yak Guru

323 Posts

Posted - 2007-03-29 : 13:42:50
When I run the following query:
select top 1 step_name,run_date,run_duration
from dbo.sysjobhistory
where job_id='3766BB4F-4E0C-400F-AA4D-33EB68CB8E03'


I get the output

Step_Name Run_date Run_duration
========= ======== ============
Subplan 20070304 1257

I learn the run_duration is an Int, it means, 12 minutes and 57 seconds in this place.

What I would like to see is how to interprete this value as 12:57.
Mind you some jobs run 11257 which I understand means, 1 hour, 12 minutes and 57 seconds.
Regards
Paresh

Regards
Paresh Motiwala
Boston, USA

pareshmotiwala
Constraint Violating Yak Guru

323 Posts

Posted - 2007-03-29 : 16:10:08
I was able to come up with this...
any comments on this or is there an easier way?

select top 1 sj.Name,char(13),char(10),' On ', sjh.server,' took ',char(13),char(10),cast(ltrim(left(str(run_duration, 6, 0),2)) as tinyint),':Hours,',
cast(ltrim(substring(str(run_duration, 6, 0),3,2)) as tinyint),':Mins,',
ltrim(right(run_duration,2)),'Seconds', char(13),char(10),' to complete.' from sysjobhistory sjh
join sysjobs as sj on sj.job_id=sjh.job_id
where sj.job_id='xyz'
and step_id=1
order by run_date desc
SET NOCOUNT OFF

Regards
Paresh Motiwala
Boston, USA
Go to Top of Page
   

- Advertisement -