|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 5:00 AM
Points: 967,
Visits: 447
|
|
Hi,
Is there anyway that we can retrieve the Last Run date of a SQL Job using T-SQL.
Thanks
Prasad Bhogadi
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 7:30 AM
Points: 6,380,
Visits: 5,432
|
|
SELECT j.[name], MAX(CAST( STUFF(STUFF(CAST(jh.run_date as varchar),7,0,'-'),5,0,'-') + ' ' + STUFF(STUFF(REPLACE(STR(jh.run_time,6,0),' ','0'),5,0,':'),3,0,':') as datetime)) AS [LastRun] FROM msdb.dbo.sysjobs j INNER JOIN msdb.dbo.sysjobhistory jh ON jh.job_id = j.job_id AND jh.step_id = 0 WHERE j.[name] = 'jobname' GROUP BY j.[name]
Far away is close at hand in the images of elsewhere. Anon.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 5:00 AM
Points: 967,
Visits: 447
|
|
Thank you David.
Prasad Bhogadi
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, July 17, 2008 10:20 AM
Points: 2,
Visits: 9
|
|
David, thank you for the post. I ran the query and it returned the date of last DTS run, do you know how to get the last "successfull" DTS run
Thanks, A
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Wednesday, April 10, 2013 10:10 PM
Points: 307,
Visits: 1,390
|
|
Based on David's script:
SELECT j.[name], MAX(CAST( STUFF(STUFF(CAST(jh.run_date as varchar),7,0,'-'),5,0,'-') + ' ' + STUFF(STUFF(REPLACE(STR(jh.run_time,6,0),' ','0'),5,0,':'),3,0,':') as datetime)) AS [LastRun], CASE jh.run_status WHEN 0 THEN 'Failed' WHEN 1 THEN 'Success' WHEN 2 THEN 'Retry' WHEN 3 THEN 'Canceled' WHEN 4 THEN 'In progress' END AS Status FROM msdb.dbo.sysjobs j INNER JOIN msdb.dbo.sysjobhistory jh ON jh.job_id = j.job_id AND jh.step_id = 0 inner join msdb.dbo.syscategories sc on j.category_id = sc.category_id WHERE sc.[name] like '%DTS%' GROUP BY j.[name], jh.run_status
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, July 17, 2008 10:20 AM
Points: 2,
Visits: 9
|
|
| Thank you very much for the script.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Tuesday, February 17, 2009 11:37 AM
Points: 68,
Visits: 23
|
|
| Do you know how to get the last datetime of SQL replication? Thank you!
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Wednesday, April 10, 2013 10:10 PM
Points: 307,
Visits: 1,390
|
|
Coop (10/28/2008) Do you know how to get the last datetime of SQL replication? Thank you!
Not sure what you asked.
There are several _history tables in distribution db, like, MSdistribution_history, MSlogreader_history, etc... You can get some info from there.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Tuesday, February 17, 2009 11:37 AM
Points: 68,
Visits: 23
|
|
| Can you please give me an example SQL Statement to use to get the last datetime of the scheduled replication? Thanks
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, February 22, 2010 9:08 AM
Points: 2,
Visits: 27
|
|
| for a lot of examples on how to query dts schedule fields see http://raoulteeuwen.blogspot.com/2008/09/query-job-last-run-status-in-ms-sql.html and the link in that blog to http://doc.ddart.net/mssql/sql70/sp_help_27.htm ... it shows you how you can check last run date, last run status etc.
|
|
|
|