<?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/"
		>
<channel>
	<title>Comments on: Repost: Watch out for SQL Server Parameter Sniffing</title>
	<atom:link href="http://elegantcode.com/2009/06/24/repost-watch-out-for-sql-server-parameter-sniffing/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2009/06/24/repost-watch-out-for-sql-server-parameter-sniffing/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=repost-watch-out-for-sql-server-parameter-sniffing</link>
	<description></description>
	<lastBuildDate>Sun, 12 Feb 2012 18:54:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
	<item>
		<title>By: Sreeni</title>
		<link>http://elegantcode.com/2009/06/24/repost-watch-out-for-sql-server-parameter-sniffing/comment-page-1/#comment-47420</link>
		<dc:creator>Sreeni</dc:creator>
		<pubDate>Fri, 03 Jul 2009 05:29:40 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2009/06/24/repost-watch-out-for-sql-server-parameter-sniffing/#comment-47420</guid>
		<description>Yes, it really help me to trouble shoot the time taking process in SSRS reports.</description>
		<content:encoded><![CDATA[<p>Yes, it really help me to trouble shoot the time taking process in SSRS reports.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://elegantcode.com/2009/06/24/repost-watch-out-for-sql-server-parameter-sniffing/comment-page-1/#comment-47190</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Thu, 25 Jun 2009 15:12:27 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2009/06/24/repost-watch-out-for-sql-server-parameter-sniffing/#comment-47190</guid>
		<description>Chris, this is a great post.  I would like to add one point.  I have run into this issue many times at the company I work for.  Where this usually becomes an issue is when you have an sp that looks like this:

CREATE PROC spReturnUsers
	@UserName NVARCHAR(20),
	@FirstName NVARCHAR(20)
AS
BEGIN
	SELECT * 
	FROM tbUsers
	WHERE (UserName = @UserName OR @Username IS NULL)
		AND (FirstName = @FirstName OR @FirstName IS NULL)
END

Now I will admit I do not have a great understanding of this so forgive me if I am wrong but what happens is this, during the execution of the above script it will scan the entire table for Username = @Username and then check if the @UserName is NULL.  This is when you get the terrible response times. On other hand when it runs fast it is checking to see if the @UserName is NULL right away.  I believe the reason why declaring the variables locally solves the problem is because SQL Server will then always check the IS NULL portion of each line first.  Whereas, if it is not declared locally SQL Server is not smart enough to look at that first.</description>
		<content:encoded><![CDATA[<p>Chris, this is a great post.  I would like to add one point.  I have run into this issue many times at the company I work for.  Where this usually becomes an issue is when you have an sp that looks like this:</p>
<p>CREATE PROC spReturnUsers<br />
	@UserName NVARCHAR(20),<br />
	@FirstName NVARCHAR(20)<br />
AS<br />
BEGIN<br />
	SELECT *<br />
	FROM tbUsers<br />
	WHERE (UserName = @UserName OR @Username IS NULL)<br />
		AND (FirstName = @FirstName OR @FirstName IS NULL)<br />
END</p>
<p>Now I will admit I do not have a great understanding of this so forgive me if I am wrong but what happens is this, during the execution of the above script it will scan the entire table for Username = @Username and then check if the @UserName is NULL.  This is when you get the terrible response times. On other hand when it runs fast it is checking to see if the @UserName is NULL right away.  I believe the reason why declaring the variables locally solves the problem is because SQL Server will then always check the IS NULL portion of each line first.  Whereas, if it is not declared locally SQL Server is not smart enough to look at that first.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dew Drop &#8211; June 25, 2009 &#124; Alvin Ashcraft's Morning Dew</title>
		<link>http://elegantcode.com/2009/06/24/repost-watch-out-for-sql-server-parameter-sniffing/comment-page-1/#comment-47187</link>
		<dc:creator>Dew Drop &#8211; June 25, 2009 &#124; Alvin Ashcraft's Morning Dew</dc:creator>
		<pubDate>Thu, 25 Jun 2009 12:48:15 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2009/06/24/repost-watch-out-for-sql-server-parameter-sniffing/#comment-47187</guid>
		<description>[...] Repost: Watch out for SQL Server Parameter Sniffing (Chris Brandsma) [...]</description>
		<content:encoded><![CDATA[<p>[...] Repost: Watch out for SQL Server Parameter Sniffing (Chris Brandsma) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron</title>
		<link>http://elegantcode.com/2009/06/24/repost-watch-out-for-sql-server-parameter-sniffing/comment-page-1/#comment-47160</link>
		<dc:creator>Aaron</dc:creator>
		<pubDate>Wed, 24 Jun 2009 19:38:36 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2009/06/24/repost-watch-out-for-sql-server-parameter-sniffing/#comment-47160</guid>
		<description>Chris, thanks for the post.  This solved a problem I had with a report.  Strange fix indeed.</description>
		<content:encoded><![CDATA[<p>Chris, thanks for the post.  This solved a problem I had with a report.  Strange fix indeed.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

