select getdate() date_time, t3.session_id, host_name, t3.status,DB_NAME(t2.database_id) DataBase_Name,
blocking_session_id AS Blocked_by,SUBSTRING(t1.text, (t2.statement_start_offset/2)+1,
((CASE t2.statement_end_offset WHEN -1 THEN DATALENGTH(t1.text) WHEN 0 THEN DATALENGTH(t1.text) ELSE t2.statement_end_offset END - t2.statement_start_offset)/2) + 1) AS command,
t3.cpu_time, t3.reads, t3.writes, wait_time, t2.wait_type, last_request_end_time,program_name, t1.objectid
from sys.dm_exec_sessions t3
left join sys.dm_exec_requests t2 on t3.session_id=t2.session_id
outer APPLY sys.dm_exec_sql_text (t2.sql_handle) t1
where t3.status not in ('sleeping','dormant') and program_name not like 'sqlagent%'
No comments:
Post a Comment