<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; 2008 &#8211; 2005 &#8211; Find Longest Running Query &#8211; TSQL &#8211; Part 2</title>
	<atom:link href="http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Sun, 12 Feb 2012 09:22:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: peterb</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-128299</link>
		<dc:creator><![CDATA[peterb]]></dc:creator>
		<pubDate>Mon, 11 Apr 2011 15:34:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-128299</guid>
		<description><![CDATA[My understanding is that sys.dm_exec_query_stats  is for archived query statistics.  I&#039;ve been using the following to monitor active long running queries and it works fine for single statements - however it seems to return hugely inflated total_elapsed_time values with some procs or functions where multiple statements are run.   I&#039;m also interested if anyone know how to find the query completion times from DMVs?

THANKS  

select     .....  
FROM sys.dm_exec_requests er 
		CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) as st
	INNER JOIN sys.dm_exec_sessions AS es
			ON es.session_id = er.session_id
	INNER JOIN sys.dm_exec_connections AS ec
			ON ec.session_id = es.session_id
	where	er.total_elapsed_time / 1000.0 &gt; @ElapsedThreshold	
ORDER BY er.total_elapsed_time DESC;]]></description>
		<content:encoded><![CDATA[<p>My understanding is that sys.dm_exec_query_stats  is for archived query statistics.  I&#8217;ve been using the following to monitor active long running queries and it works fine for single statements &#8211; however it seems to return hugely inflated total_elapsed_time values with some procs or functions where multiple statements are run.   I&#8217;m also interested if anyone know how to find the query completion times from DMVs?</p>
<p>THANKS  </p>
<p>select     &#8230;..<br />
FROM sys.dm_exec_requests er<br />
		CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) as st<br />
	INNER JOIN sys.dm_exec_sessions AS es<br />
			ON es.session_id = er.session_id<br />
	INNER JOIN sys.dm_exec_connections AS ec<br />
			ON ec.session_id = es.session_id<br />
	where	er.total_elapsed_time / 1000.0 &gt; @ElapsedThreshold<br />
ORDER BY er.total_elapsed_time DESC;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amir</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-125722</link>
		<dc:creator><![CDATA[Amir]]></dc:creator>
		<pubDate>Thu, 31 Mar 2011 00:18:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-125722</guid>
		<description><![CDATA[Hi Pinal,

I think you don&#039;t need to devide by 1000 for FrequencyPerSec]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>I think you don&#8217;t need to devide by 1000 for FrequencyPerSec</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gnana</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-86147</link>
		<dc:creator><![CDATA[Gnana]]></dc:creator>
		<pubDate>Wed, 01 Sep 2010 14:13:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-86147</guid>
		<description><![CDATA[Hi Pinal,

we are getting &quot;insufficient system memory to run this query&quot;  error. It&#039;s a SQL 2k5 sp2 on  Intel E5520 series machine. Please advise on this error...]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>we are getting &#8220;insufficient system memory to run this query&#8221;  error. It&#8217;s a SQL 2k5 sp2 on  Intel E5520 series machine. Please advise on this error&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abhijit</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-61622</link>
		<dc:creator><![CDATA[Abhijit]]></dc:creator>
		<pubDate>Tue, 23 Feb 2010 07:37:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-61622</guid>
		<description><![CDATA[I guess this query will also return the long running query. You can also add the filters to see the long running transactions.


SELECT	DATEDIFF(MINUTE, a.last_batch, GETDATE()) RunningTime,
		a.spid, a.blocked, a.waittime, db_name(a.dbid) As dbname, 
		a.last_batch, a.hostname, a.program_name, 
		a.nt_username, a.loginame, b.text as sqlstatement
FROM	sys.sysprocesses A CROSS APPLY sys.dm_exec_sql_text(a.sql_handle) B
WHERE	A.dbid &gt; 4 ----to filter system databases
ORDER BY RunningTime DESC
GO]]></description>
		<content:encoded><![CDATA[<p>I guess this query will also return the long running query. You can also add the filters to see the long running transactions.</p>
<p>SELECT	DATEDIFF(MINUTE, a.last_batch, GETDATE()) RunningTime,<br />
		a.spid, a.blocked, a.waittime, db_name(a.dbid) As dbname,<br />
		a.last_batch, a.hostname, a.program_name,<br />
		a.nt_username, a.loginame, b.text as sqlstatement<br />
FROM	sys.sysprocesses A CROSS APPLY sys.dm_exec_sql_text(a.sql_handle) B<br />
WHERE	A.dbid &gt; 4 &#8212;-to filter system databases<br />
ORDER BY RunningTime DESC<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bhaskar</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-57764</link>
		<dc:creator><![CDATA[bhaskar]]></dc:creator>
		<pubDate>Fri, 20 Nov 2009 07:25:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-57764</guid>
		<description><![CDATA[Hi,

Please add the hostname with this query.
I am not able to join sysprocess for hostname with this query.]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Please add the hostname with this query.<br />
I am not able to join sysprocess for hostname with this query.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bhaskar</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-57763</link>
		<dc:creator><![CDATA[Bhaskar]]></dc:creator>
		<pubDate>Fri, 20 Nov 2009 07:00:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-57763</guid>
		<description><![CDATA[Hi ,

Is there any method to get the host name with this query?
I am not able to connect this with sysprocesses to get the hostname.
Please help.]]></description>
		<content:encoded><![CDATA[<p>Hi ,</p>
<p>Is there any method to get the host name with this query?<br />
I am not able to connect this with sysprocesses to get the hostname.<br />
Please help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-55128</link>
		<dc:creator><![CDATA[Imran Mohammed]]></dc:creator>
		<pubDate>Sun, 23 Aug 2009 04:09:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-55128</guid>
		<description><![CDATA[@Wayne, 

Check This. 

SELECT DISTINCT TOP 10
db_name(dbid) DatabaseName, -- Added 
t.TEXT QueryName,
s.execution_count AS ExecutionCount,
s.max_elapsed_time AS MaxElapsedTime,
ISNULL(s.total_elapsed_time / 1000 / NULLIF(s.execution_count, 0), 0) AS AvgElapsedTime,
s.creation_time AS LogCreatedOn,
ISNULL(s.execution_count / 1000 / NULLIF(DATEDIFF(s, s.creation_time, GETDATE()), 0), 0) AS FrequencyPerSec
FROM sys.dm_exec_query_stats s
CROSS APPLY sys.dm_exec_sql_text( s.sql_handle ) t
ORDER BY s.max_elapsed_time DESC, ExecutionCount DESC

I dont know why database name is returned NULL some times...  Check this throughly before you use it... 

~ IM.]]></description>
		<content:encoded><![CDATA[<p>@Wayne, </p>
<p>Check This. </p>
<p>SELECT DISTINCT TOP 10<br />
db_name(dbid) DatabaseName, &#8212; Added<br />
t.TEXT QueryName,<br />
s.execution_count AS ExecutionCount,<br />
s.max_elapsed_time AS MaxElapsedTime,<br />
ISNULL(s.total_elapsed_time / 1000 / NULLIF(s.execution_count, 0), 0) AS AvgElapsedTime,<br />
s.creation_time AS LogCreatedOn,<br />
ISNULL(s.execution_count / 1000 / NULLIF(DATEDIFF(s, s.creation_time, GETDATE()), 0), 0) AS FrequencyPerSec<br />
FROM sys.dm_exec_query_stats s<br />
CROSS APPLY sys.dm_exec_sql_text( s.sql_handle ) t<br />
ORDER BY s.max_elapsed_time DESC, ExecutionCount DESC</p>
<p>I dont know why database name is returned NULL some times&#8230;  Check this throughly before you use it&#8230; </p>
<p>~ IM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wayne Nelson</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-55097</link>
		<dc:creator><![CDATA[Wayne Nelson]]></dc:creator>
		<pubDate>Fri, 21 Aug 2009 16:05:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-55097</guid>
		<description><![CDATA[I have multiple user databases. How would I modify the query to add a column showing which database the query is executing against?]]></description>
		<content:encoded><![CDATA[<p>I have multiple user databases. How would I modify the query to add a column showing which database the query is executing against?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jerry Hung</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-47279</link>
		<dc:creator><![CDATA[Jerry Hung]]></dc:creator>
		<pubDate>Tue, 24 Feb 2009 16:51:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-47279</guid>
		<description><![CDATA[Oops, don&#039;t even know my name was mentioned, but thanks Pinal

Just want to share, came over this article 02/20 &quot;usp_Worst_TSQL&quot;
It&#039;s a powerful script to find worst performing queries, with parameters

http://www.databasejournal.com/features/mssql/article.php/3802936/Finding-the-Worst-Performing-T-SQL-Statements-on-an-Instance.htm]]></description>
		<content:encoded><![CDATA[<p>Oops, don&#8217;t even know my name was mentioned, but thanks Pinal</p>
<p>Just want to share, came over this article 02/20 &#8220;usp_Worst_TSQL&#8221;<br />
It&#8217;s a powerful script to find worst performing queries, with parameters</p>
<p><a href="http://www.databasejournal.com/features/mssql/article.php/3802936/Finding-the-Worst-Performing-T-SQL-Statements-on-an-Instance.htm" rel="nofollow">http://www.databasejournal.com/features/mssql/article.php/3802936/Finding-the-Worst-Performing-T-SQL-Statements-on-an-Instance.htm</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darshan Shah</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-46782</link>
		<dc:creator><![CDATA[Darshan Shah]]></dc:creator>
		<pubDate>Tue, 17 Feb 2009 16:06:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-46782</guid>
		<description><![CDATA[This is for 2005 but what to do for sql server 2000? 
I think we can use SQL profiler for that ,we can also check the using activity monitor,sysprocess,sp_locks , sp_who2 .]]></description>
		<content:encoded><![CDATA[<p>This is for 2005 but what to do for sql server 2000?<br />
I think we can use SQL profiler for that ,we can also check the using activity monitor,sysprocess,sp_locks , sp_who2 .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sandle Wood</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-46083</link>
		<dc:creator><![CDATA[Sandle Wood]]></dc:creator>
		<pubDate>Wed, 28 Jan 2009 17:43:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-46083</guid>
		<description><![CDATA[Again one easy to understand and nice blog based on SQL server....]]></description>
		<content:encoded><![CDATA[<p>Again one easy to understand and nice blog based on SQL server&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-45932</link>
		<dc:creator><![CDATA[Matt]]></dc:creator>
		<pubDate>Fri, 23 Jan 2009 09:28:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-45932</guid>
		<description><![CDATA[Hello, 

Just delete the &quot;,&quot; before the GO command.

Thanks]]></description>
		<content:encoded><![CDATA[<p>Hello, </p>
<p>Just delete the &#8220;,&#8221; before the GO command.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: riley</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comment-45931</link>
		<dc:creator><![CDATA[riley]]></dc:creator>
		<pubDate>Fri, 23 Jan 2009 09:19:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2105#comment-45931</guid>
		<description><![CDATA[Nice blog with huge information about SQL SERVER. I just found your blog, and really enjoyed reading this post.]]></description>
		<content:encoded><![CDATA[<p>Nice blog with huge information about SQL SERVER. I just found your blog, and really enjoyed reading this post.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

