Tuesday, July 16, 2013

TSQL statement of running queries

In a SQL production environment it can happen that you see heavy transactions. With next query you can retrieve the TSQL statement of a process you see in master..sysprocesses.

SELECT Text,hostname, program_name, nt_username,*
FROM Master..sysprocesses
CROSS APPLY sys.dm_exec_sql_text (sql_handle)
WHERE Spid > 50


You can extend the WHERE clause with SPID = XX or something else you wnat to filter on.

No comments: