SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


msdb.dbo.sysjobhistory Linking


msdb.dbo.sysjobhistory Linking

Author
Message
Daniel Fountain
Daniel Fountain
SSC Eights!
SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)

Group: General Forum Members
Points: 969 Visits: 890
Hey all,

I am querying the msdb.dbo.sysjobhistory. Some of the jobs have multiple steps and run hourly.

I cant see any entry on this for a run_id or similar? Am i missing something or can you not group these entries into scheduled runs?

Dan
gbritton1
gbritton1
Say Hey Kid
Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)

Group: General Forum Members
Points: 669 Visits: 864
Have you tried joining on the sysjobs and sysjobschedules tables (on job_id)
Daniel Fountain
Daniel Fountain
SSC Eights!
SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)

Group: General Forum Members
Points: 969 Visits: 890
Yes, but that just gives you details of the jobs and the steps the job should take. How to then make it know that 5 steps that were run 2 hours ago were separate from the same 5 steps 10 minutes ago - i am not sure?
durai nagarajan
durai nagarajan
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1629 Visits: 2775
I have this script for SQL 2005 try this out
SELECT  job.Name,   
case job.description when 'No description available.' then '' else job.description end,
step.step_name,
case his.run_status when 0 then 'Failed' Else 'Success' end 'Status',
convert(varchar,convert(datetime,cast(his.run_date as varchar),106),106) 'Run Date',
case len(run_time) when 6 then SUBSTRING(convert(varchar,run_time),1,2) + ':' + SUBSTRING(convert(varchar,run_time),3,2) + ':' + SUBSTRING(convert(varchar,run_time),5,2)
when 5 then SUBSTRING(convert(varchar,run_time),1,1) + ':' + SUBSTRING(convert(varchar,run_time),2,2) + ':' + SUBSTRING(convert(varchar,run_time),4,2)
when 3 then '12' + ':0' + SUBSTRING(convert(varchar,run_time),1,1) + ':' + SUBSTRING(convert(varchar,run_time),2,2)
when 1 then '12:00:00'
else convert(varchar,run_time)
End 'Run Time',
his.run_duration,
case when his.sql_message_id <> 0 and his.sql_message_id <> 8153then his.message else '' end 'Message'
from msdb.dbo.SysJobs job,
msdb.dbo.SysJobSteps step,
msdb.dbo.SysJobHistory His
where job.enabled = 1
and job.job_id = step.job_id
and job.job_id = His.job_id
and step.step_id = His.step_id
and his.run_date = ( select top 1 his1.run_date from msdb.dbo.SysJobHistory his1
where his1.job_id = His.job_id
and step.step_id = His1.step_id
order by 1 desc
)
and his.run_time = ( select top 1 his2.run_time from msdb.dbo.SysJobHistory his2
where his2.job_id = His.job_id
and his2.run_date = his.run_date
and step.step_id = His2.step_id
order by 1 desc
)
and job.description not like 'This job is owned by a report server process%'
--and his.run_status = 0
order by his.run_status, job.Name, His.step_id



Regards
Durai Nagarajan
gbritton1
gbritton1
Say Hey Kid
Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)

Group: General Forum Members
Points: 669 Visits: 864
Each step has a unique id. Combine that with the run_time and you should have a unique running instance
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search