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


last job that ran


last job that ran

Author
Message
rightontarget
rightontarget
SSChasing Mays
SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)

Group: General Forum Members
Points: 641 Visits: 475
Hi all,
If I have a job that executed twice, how can I, using t-sql, find which one executed last?

Thanks,
Eugene
Orlando Colamatteo
Orlando Colamatteo
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39408 Visits: 14411
Huh? If one job executed twice then asking "which one executed last" does not make a lot of sense since it is the same job that executed both times.

For detailed info about jobs and job history you can look in the tables in the dbo schema in msdb with the prefix sysjob.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
rightontarget
rightontarget
SSChasing Mays
SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)

Group: General Forum Members
Points: 641 Visits: 475
Not sure why it doesn't make sense to you.
For instance you have a scheduled job that runs at 6PM daily. You have an automated email every morning reporting success/failure.
Then job broke. You made corrections and ran it MANUALLY. Now, the next morning you only want to see the report about automated jobs, not the one manual once.
That's fine, I found a way to do it. I am looking at highest instance for a given job to pick the latest.
Orlando Colamatteo
Orlando Colamatteo
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39408 Visits: 14411
eugene.pipko (11/15/2012)
Not sure why it doesn't make sense to you.
For instance you have a scheduled job that runs at 6PM daily. You have an automated email every morning reporting success/failure.
Then job broke. You made corrections and ran it MANUALLY. Now, the next morning you only want to see the report about automated jobs, not the one manual once.
That's fine, I found a way to do it. I am looking at highest instance for a given job to pick the latest.

Remember when posting that others cannot see what you see nor do they know that you have attached special meaning to the word "last" unless you explain it. Your clarification about automated versus manual job executions was excellent. If you had written in your first post what you just wrote in your most recent post you most likely would have received a response within only a few minutes. I am happy you found a path forward!

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
KylesWay
KylesWay
SSC-Enthusiastic
SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)

Group: General Forum Members
Points: 191 Visits: 367
Not sure if I'm late or not but here is one I have used:

SELECT name,
(SELECT MAX(run_date) AS MaxRunDate
FROM msdb.dbo.sysjobhistory AS B
WHERE (job_id = A.job_id)) AS MaxDate,
(SELECT MAX(run_time) AS MaxRunTime
FROM msdb.dbo.sysjobhistory AS B
WHERE (job_id = A.job_id)) AS MaxTime
FROM msdb.dbo.sysjobs AS A
WHERE (name = 'YourJobName')
RedDoorSQL
RedDoorSQL
SSC Veteran
SSC Veteran (264 reputation)SSC Veteran (264 reputation)SSC Veteran (264 reputation)SSC Veteran (264 reputation)SSC Veteran (264 reputation)SSC Veteran (264 reputation)SSC Veteran (264 reputation)SSC Veteran (264 reputation)

Group: General Forum Members
Points: 264 Visits: 221
SELECT
sj.name,
so.name,
max(run_date) [LastRunDate]
FROM
msdb.dbo.sysjobs sj
inner join msdb.dbo.sysjobhistory sjh
on sj.job_id =sjh.job_id
inner join msdb.dbo.sysoperators so
on sj.notify_email_operator_id = so.id
GROUP BY
sj.name,
so.name
Snigdha Vartak
Snigdha Vartak
Say Hey Kid
Say Hey Kid (700 reputation)Say Hey Kid (700 reputation)Say Hey Kid (700 reputation)Say Hey Kid (700 reputation)Say Hey Kid (700 reputation)Say Hey Kid (700 reputation)Say Hey Kid (700 reputation)Say Hey Kid (700 reputation)

Group: General Forum Members
Points: 700 Visits: 247
It worked. Thanks for the post.
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