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 2000 Forums
 SQL Server Development (2000)
 exporting job history to a table

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2008-09-30 : 10:07:22
Hi

I have sql server job that runs on daily basis. What i need is to capture the execution time the job takes on each day in a table
i.e the job history details should be exported to a table. Is this possible.?

thanks in advace

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-09-30 : 10:43:46
That info is already stored in a table: msdb..sysjobhistory. The [run_date] and [run_duration] values are stored in a funky format though. You may need to get creative to make use of them.

Be One with the Optimizer
TG
Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2008-10-03 : 16:56:03
quote:
Originally posted by TG

That info is already stored in a table: msdb..sysjobhistory. The [run_date] and [run_duration] values are stored in a funky format though. You may need to get creative to make use of them.

Be One with the Optimizer
TG



Thanks for the tip.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-03 : 16:59:54
This might help you with the run_date and run_duration formats. It's a query I was running earlier this week to determine what was running when our customers were reporting issues.



select job_name, run_datetime, run_duration
from
(
select job_name, DATEADD(hh, -7, run_datetime) as run_datetime,
SUBSTRING(run_duration, 1, 2) + ':' + SUBSTRING(run_duration, 3, 2) + ':' +
SUBSTRING(run_duration, 5, 2) AS run_duration
from
(
select
j.name as job_name,
run_datetime = CONVERT(DATETIME, RTRIM(run_date)) +
(run_time * 9 + run_time % 10000 * 6 + run_time % 100 * 10) / 216e4,
run_duration = RIGHT('000000' + CONVERT(varchar(6), run_duration), 6)
from msdb..sysjobhistory h
inner join msdb..sysjobs j
on h.job_id = j.job_id
where run_date = '20080930' or run_date = '20081001'
) t
) t
where
run_datetime between '10/01/2008 00:00' and '10/01/2008 05:00' and
job_name <> 'backup transaction logs'
order by run_datetime


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -