<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx</link><description>As with all of the blog posts I keep meaning to write -- I keep a list and given the infrequency with which I've been posting lately, it's getting quite large -- this script has been on the queue for quite some time. So here I find myself with a spare</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#4309</link><pubDate>Wed, 02 Jan 2008 04:47:13 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4309</guid><dc:creator>Thomas Williams</dc:creator><description>&lt;p&gt;G'day Adam, this is a handly script - the only thing I would add is the option to ignore whoever's running the script (unless they were blocking or being blocked, maybe) and the database name.&lt;/p&gt;
&lt;p&gt;Cheers, and Happy New Year, &lt;/p&gt;
&lt;p&gt;Thomas&lt;/p&gt;
</description></item><item><title>re: A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#4315</link><pubDate>Wed, 02 Jan 2008 15:17:28 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4315</guid><dc:creator>jerryhung</dc:creator><description>&lt;p&gt;Great script, thank you&lt;/p&gt;
&lt;p&gt;I had my own modified sp_who2 to return data I want, but not as detailed as yours&lt;/p&gt;
&lt;p&gt;I added in the db_name (the only way I know how, if there's a better way feel free)&lt;/p&gt;
&lt;p&gt;SELECT&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.session_id,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.host_name,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.login_name,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.start_time,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.totalReads,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.totalWrites,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.totalCPU,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.writes_in_tempdb,&lt;/p&gt;
&lt;p&gt;	x.dbname,	-- new addition by Jerry&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SELECT&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;text AS [text()]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FROM sys.dm_exec_sql_text(x.sql_handle)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FOR XML PATH(''), TYPE&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;) AS sql_text,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;COALESCE(x.blocking_session_id, 0) AS blocking_session_id,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SELECT&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;p.text&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FROM&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SELECT&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MIN(sql_handle) AS sql_handle&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FROM sys.dm_exec_requests r2&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;WHERE&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r2.session_id = x.blocking_session_id&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;) AS r_blocking&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CROSS APPLY&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SELECT&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;text AS [text()]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FROM sys.dm_exec_sql_text(r_blocking.sql_handle)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FOR XML PATH(''), TYPE&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;) p (text)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;) AS blocking_text&lt;/p&gt;
&lt;p&gt;FROM&lt;/p&gt;
&lt;p&gt;(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;SELECT&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.session_id,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.host_name,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.login_name,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.start_time,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.sql_handle,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.blocking_session_id,&lt;/p&gt;
&lt;p&gt;		dbname = DB_NAME(r.database_id),	-- new addition by Jerry&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SUM(r.reads) AS totalReads,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SUM(r.writes) AS totalWrites,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SUM(r.cpu_time) AS totalCPU,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SUM(tsu.user_objects_alloc_page_count + tsu.internal_objects_alloc_page_count) AS writes_in_tempdb&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;FROM sys.dm_exec_requests r -- select * FROM sys.dm_exec_requests&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;JOIN sys.dm_exec_sessions s ON s.session_id = r.session_id&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;JOIN sys.dm_db_task_space_usage tsu ON s.session_id = tsu.session_id and r.request_id = tsu.request_id&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;WHERE r.status IN ('running', 'runnable', 'suspended')&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;GROUP BY&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.session_id,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.host_name,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.login_name,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.start_time,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.sql_handle,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.blocking_session_id&lt;/p&gt;
&lt;p&gt;		,DB_NAME(r.database_id)	-- new addition by Jerry&lt;/p&gt;
&lt;p&gt;) x&lt;/p&gt;
</description></item><item><title>re: A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#4316</link><pubDate>Wed, 02 Jan 2008 16:08:08 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4316</guid><dc:creator>Ranga</dc:creator><description>&lt;p&gt;Excellent script...Thanks.&lt;/p&gt;
</description></item><item><title>re: A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#4317</link><pubDate>Wed, 02 Jan 2008 16:32:15 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4317</guid><dc:creator>Vamsi</dc:creator><description>&lt;p&gt;Handy script especially when we have sp_who2 returning &amp;gt; 1000 rows.&lt;/p&gt;
&lt;p&gt;Added for xml to my script, good tip to get the text back as a link. Command type &amp;lt;&amp;lt; sys.dm_exec_requests.Command&amp;gt;&amp;gt;would be helpful too..&lt;/p&gt;
</description></item><item><title>re: A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#4321</link><pubDate>Wed, 02 Jan 2008 17:44:38 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4321</guid><dc:creator>Aaron Bertrand</dc:creator><description>&lt;p&gt;This might be useful to people too; I created a more flexible version of sp_who2 in September 2006, which I've been meaning to go back and update (because the version I actually use has been enhanced a bit). &amp;nbsp;But still worth a look IMHO:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://sqlserver2005.databases.aspfaq.com/better-sp-who2.html"&gt;http://sqlserver2005.databases.aspfaq.com/better-sp-who2.html&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#4418</link><pubDate>Sat, 05 Jan 2008 18:46:43 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4418</guid><dc:creator>aaron</dc:creator><description>&lt;p&gt;If you put the text into a comment node rather then a text node entities will not be escaped. e.g. &lt;/p&gt;
&lt;p&gt;SELECT&lt;/p&gt;
&lt;p&gt; &amp;nbsp;text AS [comment()]&lt;/p&gt;
&lt;p&gt;FROM sys.dm_exec_sql_text(x.sql_handle)&lt;/p&gt;
&lt;p&gt;FOR XML PATH(''), TYPE&lt;/p&gt;
&lt;p&gt;You will have to deal with the xml comment wrappers (&amp;lt;!-- and --&amp;gt;) around the text but they will always be in the same place.&lt;/p&gt;
&lt;p&gt;Hope that helps.&lt;/p&gt;
</description></item><item><title>re: A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#4430</link><pubDate>Sun, 06 Jan 2008 16:53:08 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4430</guid><dc:creator>Kevin Boles</dc:creator><description>&lt;p&gt;In one spid I did this (pubs, sql2005):&lt;/p&gt;
&lt;p&gt;BEGIN TRAN&lt;/p&gt;
&lt;p&gt;update authors set au_lname = 'asdf'&lt;/p&gt;
&lt;p&gt;In a second spid I did this:&lt;/p&gt;
&lt;p&gt;select * from authors&lt;/p&gt;
&lt;p&gt;Running your query did not show the blocking spid nor (and more importantly) did it show the blocking sql query's text (although it did show that it was spid NN doing the blocking). &amp;nbsp;Any way we can get it to pick up that blocking spid's text even though said spid is in a SLEEPING state?&lt;/p&gt;
</description></item><item><title>re: A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#4431</link><pubDate>Sun, 06 Jan 2008 19:38:24 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4431</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Thanks, all, for the great comments! &amp;nbsp;Responses inline:&lt;/p&gt;
&lt;p&gt;Thomas W: Add an outer WHERE clause: &amp;quot;WHERE x.SessionId &amp;lt;&amp;gt; @@SPID&amp;quot;&lt;/p&gt;
&lt;p&gt;JerryHung: Great addition.&lt;/p&gt;
&lt;p&gt;Arron B: Awesome!&lt;/p&gt;
&lt;p&gt;Aaron &amp;lt;no last name&amp;gt;: Thanks, that's great!!&lt;/p&gt;
&lt;p&gt;Kevin: Great feedback. &amp;nbsp;How about if we change the inner WHERE clause to: &lt;/p&gt;
&lt;p&gt;&amp;quot;WHERE r.status IN ('running', 'runnable', 'suspended') OR r.blocking_session_id IS NOT NULL&amp;quot;&lt;/p&gt;
&lt;p&gt;Any other situations in which a sleeping session might be interesting to see?&lt;/p&gt;
</description></item><item><title>re: A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#4481</link><pubDate>Wed, 09 Jan 2008 20:56:31 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4481</guid><dc:creator>Javier Villegas</dc:creator><description>&lt;p&gt;Very useful script!!!! Thanks a lot!. I modified it a little bit to show just the T-SQL statement (in xml format) instead of the whole procedure. Also totalElapsedTime , db name and object name are now included and current spid was excluded.&lt;/p&gt;
&lt;p&gt;SELECT&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.session_id,&lt;/p&gt;
&lt;p&gt;	COALESCE(x.blocking_session_id, 0) AS blocking_session_id,	&lt;/p&gt;
&lt;p&gt;	x.Status,	&lt;/p&gt;
&lt;p&gt;	x.TotalCPU,&lt;/p&gt;
&lt;p&gt;	x.Start_time,&lt;/p&gt;
&lt;p&gt;	x.totalElapsedTime,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.totalReads,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.totalWrites, &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.Writes_in_tempdb,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;(	SELECT substring(text,x.statement_start_offset/2, &lt;/p&gt;
&lt;p&gt;			(case when x.statement_end_offset = -1 &lt;/p&gt;
&lt;p&gt;			then len(convert(nvarchar(max), text)) * 2 &lt;/p&gt;
&lt;p&gt;			else x.statement_end_offset end - x.statement_start_offset)/2)&lt;/p&gt;
&lt;p&gt;		FROM sys.dm_exec_sql_text(x.sql_handle)&lt;/p&gt;
&lt;p&gt;		FOR XML PATH(''), TYPE &amp;nbsp; ) AS text,&lt;/p&gt;
&lt;p&gt;	db_name(x.database_id) as DBName ,&lt;/p&gt;
&lt;p&gt;	(SELECT object_name(objectid) FROM sys.dm_exec_sql_text(x.sql_handle)) as ObjName,		&lt;/p&gt;
&lt;p&gt;	x.Wait_type,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.Login_name, &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;x.Host_name, &amp;nbsp; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;( &amp;nbsp; SELECT &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;p.text&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FROM &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SELECT &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MIN(sql_handle) AS sql_handle&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FROM sys.dm_exec_requests r2&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;WHERE &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r2.session_id = x.blocking_session_id&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;) AS r_blocking&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CROSS APPLY&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(&lt;/p&gt;
&lt;p&gt;		SELECT substring(text,x.statement_start_offset/2, &lt;/p&gt;
&lt;p&gt;			(case when x.statement_end_offset = -1 &lt;/p&gt;
&lt;p&gt;			then len(convert(nvarchar(max), text)) * 2 &lt;/p&gt;
&lt;p&gt;			else x.statement_end_offset end - x.statement_start_offset)/2)&lt;/p&gt;
&lt;p&gt;		FROM sys.dm_exec_sql_text(r_blocking.sql_handle)&lt;/p&gt;
&lt;p&gt;		FOR XML PATH(''), TYPE&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;) p (text)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;) AS Blocking_text &amp;nbsp;&lt;/p&gt;
&lt;p&gt;FROM&lt;/p&gt;
&lt;p&gt;( &amp;nbsp; SELECT &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.session_id,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.host_name,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.login_name,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.start_time,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.sql_handle,&lt;/p&gt;
&lt;p&gt;		r.database_id,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.blocking_session_id,&lt;/p&gt;
&lt;p&gt;		r.wait_type,&lt;/p&gt;
&lt;p&gt;		r.status,&lt;/p&gt;
&lt;p&gt;		r.statement_start_offset,&lt;/p&gt;
&lt;p&gt;		r.statement_end_offset,				&lt;/p&gt;
&lt;p&gt;		SUM(r.total_elapsed_time) as totalElapsedTime,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SUM(r.reads) AS totalReads,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SUM(r.writes) AS totalWrites,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SUM(r.cpu_time) AS totalCPU,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SUM(tsu.user_objects_alloc_page_count + tsu.internal_objects_alloc_page_count) AS writes_in_tempdb&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;FROM sys.dm_exec_requests r&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;JOIN sys.dm_exec_sessions s ON s.session_id = r.session_id&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;JOIN sys.dm_db_task_space_usage tsu ON s.session_id = tsu.session_id and r.request_id = tsu.request_id&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;WHERE r.status IN ('running', 'runnable', 'suspended')&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;GROUP BY&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.session_id,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.host_name,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.login_name,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.start_time,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.sql_handle,&lt;/p&gt;
&lt;p&gt;		r.database_id,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r.blocking_session_id,&lt;/p&gt;
&lt;p&gt;		r.wait_type,&lt;/p&gt;
&lt;p&gt;		r.status,&lt;/p&gt;
&lt;p&gt;		r.statement_start_offset,&lt;/p&gt;
&lt;p&gt;		r.statement_end_offset&lt;/p&gt;
&lt;p&gt;) x&lt;/p&gt;
&lt;p&gt;where x.session_id &amp;lt;&amp;gt; @@spid&lt;/p&gt;
&lt;p&gt;order by x.totalCPU desc&lt;/p&gt;
</description></item><item><title>re: A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#4500</link><pubDate>Fri, 11 Jan 2008 20:14:33 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4500</guid><dc:creator>Pardini</dc:creator><description>&lt;p&gt;This is very interesting. I ran your query and compared it to SQL Management Studio's Activity Monitor, when running an ALTER TABLE statement. AM reports correctly the statment being run, which was&lt;/p&gt;
&lt;p&gt;ALTER TABLE dbo.xx ALTER COLUMN yyy FLOAT NULL&lt;/p&gt;
&lt;p&gt;But your query returned something very interesting:&lt;/p&gt;
&lt;p&gt;UPDATE [zzz].[dbo].[xxx] SET [yyy] = [yyy]&lt;/p&gt;
&lt;p&gt;Which makes some sense.&lt;/p&gt;
&lt;p&gt;This batch really took around half an hour running, and I'm sure it's the same batch. Do you think there's a way to get to the original SQL? Not the 'underlying' SQL isn't interesting...&lt;/p&gt;
</description></item><item><title>re: A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#4530</link><pubDate>Mon, 14 Jan 2008 14:56:54 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4530</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Pardini:&lt;/p&gt;
&lt;p&gt;AM uses DBCC INPUTBUFFER, which is the only way I'm aware of to get that information. &amp;nbsp;Unfortunately, the DBCC command does not play well with DMVs, so it can't be integrated into this script. &amp;nbsp;Please vote here:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=322262"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=322262&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#8499</link><pubDate>Fri, 22 Aug 2008 19:30:53 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:8499</guid><dc:creator>Michael B</dc:creator><description>&lt;p&gt;I get this error on one of my servers. &amp;nbsp;FWIW, it is running in compatability mode 80 on a couple databases, but most are 90.&lt;/p&gt;
&lt;p&gt;Msg 6841, Level 16, State 1, Line 1&lt;/p&gt;
&lt;p&gt;FOR XML could not serialize the data for node 'NoName' because it contains a character (0x001C) which is not allowed in XML. To retrieve this data using FOR XML, convert it to binary, varbinary or image data type and use the BINARY BASE64 directive.&lt;/p&gt;
</description></item><item><title>A Gift of Script for 2009: Who is Active, Redux</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#10842</link><pubDate>Wed, 31 Dec 2008 15:33:51 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:10842</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Last year on December 31 I posted part of a larger monitoring script that I had been working on for a&lt;/p&gt;
</description></item><item><title>A year in review, The 31 best blog posts on SQLBlog for 2008</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#10845</link><pubDate>Wed, 31 Dec 2008 15:37:49 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:10845</guid><dc:creator>Denis Gobo</dc:creator><description>&lt;p&gt;Wow, it has been already a year since I wrote A year in review, The 21 + 1 best blog posts on SQLBlog&lt;/p&gt;
</description></item><item><title>Who is Active? v8.40 - Now With Delta Power!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#13008</link><pubDate>Mon, 30 Mar 2009 16:53:40 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13008</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;It has been only a month and a half since I posted the last version of Who is Active? ( v7.30 ), but&lt;/p&gt;
</description></item><item><title>A Brief History of Monitoring (A Month of Activity Monitoring, Part 1 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx#35057</link><pubDate>Wed, 20 Apr 2011 14:43:26 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:35057</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;This post is part 1 of a 30-part series about the Who is Active stored procedure. A new post will run&lt;/p&gt;
</description></item></channel></rss>