SQL Processes, sys.dm_exec_connections and last sql statement

Last SPIDs, their statement, network packet size.

SELECT  c.session_id,
        s.host_name,
        s.login_name,
        [LastStatement].[[text]],
        c.net_packet_size,
        s.login_time,
        s.status,
        d.name
FROM    sys.dm_exec_connections c
INNER JOIN sys.dm_exec_sessions s
ON      c.session_id = s.session_id
CROSS APPLY sys.dm_exec_sql_text(most_recent_sql_handle) AS LastStatement
LEFT OUTER JOIN
	sys.databases d on d.database_id = [LastStatement].dbid
ORDER BY s.[status],
        s.login_time DESC,
        s.[host_name]
  
--

Source

Comments are closed.

Post Navigation