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 2008 Forums
 Transact-SQL (2008)
 SQL Agent history (sysjobhistory and sysjobs)

Author  Topic 

Nixter
Starting Member

5 Posts

Posted - 2015-04-30 : 12:20:37
I have a vexing problem. I am trying to track metadata on some overnight jobs, but when I predicate on run_date I get all steps that ran for the job that kicked off that evening, and the rest of the steps for the job that kicked off the night before.

I am trying to join on the correct table/field to pull - "these are all the steps for this job that started at this time". In this case - I want all steps for the job that started on 03/27. Here I am getting all steps that started and ran on 03/27 only before midnight, the rest of the steps are those that ran on 03/27, but were kicked off on 03/26

What am I missing here? Code and screenshots below (job detail names were blanked out on the insistence of the client)..

Thanks in advance!




SELECT sj.[name]
,sjh.step_id
, sjh.step_name
, sjh.run_date
, sjh.run_time
, sjh.run_duration

FROM msdb.dbo.sysjobs sj

INNER JOIN msdb.dbo.sysjobhistory sjh
ON sj.job_id = sjh.job_id

WHERE [name] = 'Reports13 Base Tables Update'
and run_date = 20150327
ORDER BY step_id DESC



   

- Advertisement -