SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Simple Process Information
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3451 Posts

Posted - 10/25/2011 :  09:51:32  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000