Session complete status and estimated completion time

,

A small retake on the popular script which tells how much more time a running session will take to complete (only if the session reports percent_complete status).

SELECT servername = @@SERVERNAME, 
 der.session_id, 
 der.start_time, 
 der.[status], 
 der.percent_complete, 
 dbname = Db_name(der.database_id), 
 der.last_wait_type, 
 der.blocking_session_id, 
 runningsince=Datediff(MINUTE, der.start_time, Getdate()), 
 runningforanother = CASE percent_complete 
 WHEN 0 THEN 0 
 ELSE ( ( ( Datediff(MINUTE, start_time, Getdate()) 
 * 100 ) 
 / percent_complete ) - ( 
 Datediff(MINUTE, start_time, Getdate( 
 )) ) ) 
 END, 
 der.command, 
 st.[text] 
FROM sys.dm_exec_requests der 
 CROSS APPLY sys.dm_exec_sql_text(der.sql_handle) st 
WHERE session_id > 50 
 AND session_id <> @@SPID

Rate

3 (3)

Share

Share

Rate

3 (3)