Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Script Library
 Simple Process Information

Author  Topic 

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-10-25 : 09:51:32
Simple script to return the sql text for currently running processes.

SELECT
sp.[spid] AS [SPID]
, sp.[blocked] AS [Blocked]
, sp.[waittime] AS [WaitTime]
, sp.[lastwaittype] AS [LastWaitType]
, DB_NAME(sp.[dbid]) AS [DBName]
, sp.[cpu] AS [CPU]
, sp.[physical_io] AS [PysicalIO]
, sp.[last_batch] AS [LastBatch]
, CASE sp.[open_tran] WHEN 1 THEN 'IN TRANSACTION' ELSE '---' END AS [Transaction Status]
, sp.[status] AS [Status]
, sp.[hostname] AS [Hostname]
, sp.[program_name] AS [ProgramName]
, sp.[cmd] AS [CommandStatus]
, sp.[loginame] AS [LoginName]
, st.[SqlText]
FROM
sys.sysprocesses AS sp
CROSS APPLY (
SELECT [TEXT] AS [SqlText]
FROM sys.dm_exec_sql_text(sp.[sql_handle])
)
AS st
ORDER BY
sp.[blocked] DESC
, CASE WHEN DB_NAME(sp.[dbid]) = 'tempdb' THEN 1 ELSE 0 END
, sp.[cpu] DESC
, sp.[physical_io] DESC


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
   

- Advertisement -