TSQL to get current executing statements - SQL Server 2005

Published 12 February 08 01:27 PM | SQL Master 

Using SP_WHO or SP_WHO2 is a common way to get list of executing processes currently on the server, within SQL Server 2005 you could take advantage of DMV that lists currently-executing statements.

select r.session_id
,status
,substring(qt.text,r.statement_start_offset/2,
(case when r.statement_end_offset = -1
then len(convert(nvarchar(max), qt.text)) * 2
else r.statement_end_offset end - r.statement_start_offset)/2)
as query_text   --- this is the statement executing right now
,qt.dbid
,qt.objectid
,r.cpu_time
,r.total_elapsed_time
,r.reads
,r.writes
,r.logical_reads
,r.scheduler_id
from sys.dm_exec_requests r
cross apply sys.dm_exec_sql_text(sql_handle) as qt
where r.session_id > 50
order by r.scheduler_id, r.status, r.session_id

A status equal to runnable indicates that the user waiting on the CPU. Note that each scheduler has its own runnable queue.  

Comments

# Other SQL Server Blogs around the Web said on February 12, 2008 1:36 PM:

Using SP_WHO or SP_WHO2 is a common way to get list of executing processes currently on the server, within

# SQL Server Transact-SQL (SSQA.net) : TSQL to get current executing statements - SQL Server 2005 said on February 12, 2008 2:50 PM:

PingBack from http://sqlserver-qa.net/blogs/t-sql/archive/2008/02/12/3428.aspx

# TrackBack said on February 19, 2008 8:03 AM:
# http://sqlserver-qa.net/blogs/t-sql/archive/2008/02/12/3428.aspx said on March 26, 2008 1:52 AM:

PingBack from http://frankthefrank.info/entry.php?id=kwws%3d22vtovhuyhu0td1qhw2eorjv2w0vto2dufklyh2533%3b2352452675%3b1dvs%7b

Anonymous comments are disabled

About SQL Master

**__________________________________** SQL Server MVP, Sr. DBA & industry expert. - Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it. It is also a power and you will gain by sharing it.