Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

last job that ran Expand / Collapse
Author
Message
Posted Wednesday, November 14, 2012 10:51 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 1:13 PM
Points: 100, Visits: 338
Hi all,
If I have a job that executed twice, how can I, using t-sql, find which one executed last?

Thanks,
Eugene
Post #1384771
Posted Thursday, November 15, 2012 6:44 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, August 23, 2014 8:34 AM
Points: 7,097, Visits: 12,601
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
Post #1385129
Posted Thursday, November 15, 2012 9:03 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 1:13 PM
Points: 100, Visits: 338
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.
Post #1385227
Posted Thursday, November 15, 2012 9:11 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, August 23, 2014 8:34 AM
Points: 7,097, Visits: 12,601
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
Post #1385230
Posted Thursday, November 15, 2012 10:18 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, August 21, 2014 9:06 AM
Points: 163, 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')
Post #1385264
Posted Tuesday, November 20, 2012 7:11 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 7:49 AM
Points: 70, Visits: 189
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
Post #1386896
Posted Tuesday, August 20, 2013 2:55 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, July 17, 2014 3:41 PM
Points: 522, Visits: 234
It worked. Thanks for the post.
Post #1486442
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse