sqlrx logo
SQLRx® Tip of the Month
 
 
July 2010
Greetings!
 
DBA's need to know when it is safe to stop services or to do other work. It is preferable to do such things when no jobs are running to prevent job failures and data integrity issues.  Check out the query below to help.
 
And don't forget to regularly monitor the 11 VitalSigns used by SQLRx to debug performance bottlenecks.
 
______________________________________________________________________________
SQL 2008  SQL Server Administration:  Find the next time that any enabled job will run. Run the query below to return a list of jobs on any SQL Server along with the last run duration and next run time.  

 

 
 

USE msdb

GO

SET NOCOUNT ON;

SELECT CONVERT(VARCHAR(20),SERVERPROPERTY('ServerName')) AS ServerName,

j.name AS job_name,

CONVERT(VARCHAR(10),CONVERT(DATETIME,RTRIM(19000101))+(jh.run_duration * 9 + jh.run_duration % 10000 * 6 + jh.run_duration % 100 * 10) / 216e4,108) AS last_run_duration,

ja.next_scheduled_run_date

FROM msdb.dbo.sysjobactivity ja

LEFT JOIN msdb.dbo.sysjobhistory jh ON ja.job_history_id = jh.instance_id

join msdb.dbo.sysjobs_view j ON ja.job_id = j.job_id

WHERE ja.session_id=(SELECT MAX(session_id) FROM msdb.dbo.sysjobactivity)

AND j.enabled = 1

ORDER BY job_name;

SET NOCOUNT OFF;

GO

 

____________________________________________________________ 

SQLRx is a part of www.msdev.com, a Microsoft training site!  Check the site periodically to view new training videos.
 
If you have a SQL question you'd like us to answer, and possibly use for the next SQLRx Tip of the Month or msdev video, email it to us!  If you missed any of our previous tips, you can view them here.
 
For assistance or more information on optimizing your SQL Server Environment, visit us at www.sqlrx.com or email Lori Brown at lorib@isi85.com.  

Sincerely,

Lori Brown | SQLRx Senior Consultant | Integrated Services, Inc.
4144 N. Central Expwy, Suite 430  |  Dallas, TX  75204
Phone: 214.526.7680 x 113 | lorib@isi85.com 
 
 
Integrated Services, Inc.                                    
2008 winner logo small
Turning Data Into Profit
 
25 Years of Credibility & Trust
 

Join our email list          Check out our events          SQLRx Downloads