﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 7,2000 / T-SQL  / T-SQL statement to return SQL Job Last Run Date / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 20:42:28 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>Do you have the script please to use sysjobactivity? I would like to bring all the jobs with their names, steps, and the status, last run time, even if there is no history, or the jobs is disabled, not scheduled</description><pubDate>Fri, 01 Feb 2013 16:53:23 GMT</pubDate><dc:creator>Golova</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>Word of warning :  if the history has been purged/deleted then sysjobhistory will not display the same data as "Job Activity Monitor" i.e. "Job Activity Monitor" will display a last run date but this is not obtainable from running queries against sysjobhistory where the history has been purged because it just won't exist. Use sysjobactivity to obtain the "real" last run date and to be in agreement with "Job Activity Monitor".Try it; create a test job, run it a few times, manually delete the latest history records then run your query using sysjobhistory. You will find that your queries report an earlier last run time than SQL's "Job Activity Monitor".Does it matter ? Well it may do, I noticed this problem when deciding which jobs could be deleted. It seemed that some jobs were never run but this was not the case as the history had been deleted.</description><pubDate>Fri, 12 Aug 2011 10:39:09 GMT</pubDate><dc:creator>Preet_S</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>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],MAX(CAST(STUFF(STUFF(CAST(sjs.next_run_date as varchar),7,0,'-'),5,0,'-') + ' ' + STUFF(STUFF(REPLACE(STR(sjs.next_run_time,6,0),' ','0'),5,0,':'),3,0,':') as datetime)) AS [NextRun],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 StatusFROM 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 scon j.category_id = sc.category_idINNER JOIN MSDB.dbo.sysjobschedules sjson j.job_id = sjs.Job_idGROUP BY j.[name], jh.run_status</description><pubDate>Wed, 01 Sep 2010 05:17:56 GMT</pubDate><dc:creator>ramarkishna </dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>Thank you for the script Wildcat, it's very useful for me!</description><pubDate>Mon, 08 Jun 2009 07:19:30 GMT</pubDate><dc:creator>lucazav</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>Thank you.  That's exactly what I was looking for.</description><pubDate>Mon, 12 Jan 2009 09:44:16 GMT</pubDate><dc:creator>James B-487162</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>[code]SELECT j.[name], 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 (SELECT a.job_id,MAX(a.instance_id) As [instance_id] FROM msdb.dbo.sysjobhistory a WHERE a.step_id = 0 GROUP BY a.job_id) b INNER JOIN msdb.dbo.sysjobhistory jh ON jh.instance_id=b.instance_id INNER JOIN msdb.dbo.sysjobs j ON j.job_id = jh.job_id [/code]</description><pubDate>Mon, 12 Jan 2009 09:35:26 GMT</pubDate><dc:creator>David Burrows</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>Thanks for posting this script.  I'm having trouble modifying it to my use though.  I'm trying to create a script that I can have dbmail run to email me the last run status of every job.  The script given, if I remove the where section works, except it gives the last run for each type of status.  If there's been a failure and a success within it's history it shows both with dates.Any ideas on how I can just have it show the late run status and time?</description><pubDate>Mon, 12 Jan 2009 08:54:55 GMT</pubDate><dc:creator>James B-487162</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>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.</description><pubDate>Fri, 28 Nov 2008 04:36:21 GMT</pubDate><dc:creator>raoul.teeuwen</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>Can you please give me an example SQL Statement to use to get the last datetime of the scheduled replication? Thanks</description><pubDate>Thu, 30 Oct 2008 16:19:00 GMT</pubDate><dc:creator>Coop-546061</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>[quote][b]Coop (10/28/2008)[/b][hr]Do you know how to get the last datetime of SQL replication? Thank you![/quote]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.</description><pubDate>Thu, 30 Oct 2008 12:35:33 GMT</pubDate><dc:creator>Wildcat</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>Do you know how to get the last datetime of SQL replication? Thank you!</description><pubDate>Tue, 28 Oct 2008 20:27:42 GMT</pubDate><dc:creator>Coop-546061</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>Thank you very much for the script.</description><pubDate>Mon, 16 Jun 2008 13:04:12 GMT</pubDate><dc:creator>azeem.anchamparuthi</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>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 StatusFROM 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 scon j.category_id = sc.category_idWHERE sc.[name] like '%DTS%'GROUP BY j.[name], jh.run_status</description><pubDate>Thu, 12 Jun 2008 13:53:38 GMT</pubDate><dc:creator>Wildcat</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>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 runThanks,A</description><pubDate>Thu, 12 Jun 2008 11:32:09 GMT</pubDate><dc:creator>azeem.anchamparuthi</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>Thank you David.</description><pubDate>Mon, 15 Oct 2007 06:57:43 GMT</pubDate><dc:creator>Prasad Bhogadi</dc:creator></item><item><title>RE: T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>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] </description><pubDate>Mon, 15 Oct 2007 06:52:13 GMT</pubDate><dc:creator>David Burrows</dc:creator></item><item><title>T-SQL statement to return SQL Job Last Run Date</title><link>http://www.sqlservercentral.com/Forums/Topic410789-8-1.aspx</link><description>Hi,Is there anyway that we can retrieve the Last Run date of a SQL Job using T-SQL.Thanks</description><pubDate>Mon, 15 Oct 2007 06:28:29 GMT</pubDate><dc:creator>Prasad Bhogadi</dc:creator></item></channel></rss>