|
|
|
Valued Member
      
Group: General Forum Members
Last Login: 2 days ago @ 9:52 AM
Points: 69,
Visits: 213
|
|
Hi all, If I have a job that executed twice, how can I, using t-sql, find which one executed last?
Thanks, Eugene
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 8:26 AM
Points: 6,737,
Visits: 11,791
|
|
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
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: 2 days ago @ 9:52 AM
Points: 69,
Visits: 213
|
|
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.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 8:26 AM
Points: 6,737,
Visits: 11,791
|
|
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
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 2:54 PM
Points: 95,
Visits: 282
|
|
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')
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: 2 days ago @ 4:09 AM
Points: 44,
Visits: 132
|
|
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
|
|
|
|