﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Virgilio Licovali Bustos Ramirez  / Slow SP with date parameters solved. / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 11:47:57 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Slow SP with date parameters solved.</title><link>http://www.sqlservercentral.com/Forums/Topic911108-2685-1.aspx</link><description>I had this same problem.  I simply copied the code in the SPROC and then dropped the object.  Lastly, I recreated the SPROC and everything ran fine.</description><pubDate>Mon, 03 May 2010 07:43:53 GMT</pubDate><dc:creator>brandonregister</dc:creator></item><item><title>RE: Slow SP with date parameters solved.</title><link>http://www.sqlservercentral.com/Forums/Topic911108-2685-1.aspx</link><description>On the subject of parameter sniffing, here's a good article that describes how that works (and best of all, how it can go wrong!)http://www.sqlpointers.com/2006/11/parameter-sniffing-stored-procedures.html</description><pubDate>Wed, 28 Apr 2010 08:32:12 GMT</pubDate><dc:creator>christopher.gray</dc:creator></item><item><title>RE: Slow SP with date parameters solved.</title><link>http://www.sqlservercentral.com/Forums/Topic911108-2685-1.aspx</link><description>It might be parameter sniffing.  If you do what Christopher suggested this will resolve the issue with parameter sniffing.  I think there are other ways to resolve the issue as well, but don't recall them right now.  Just google parameter sniffing.</description><pubDate>Wed, 28 Apr 2010 08:18:10 GMT</pubDate><dc:creator>arussell_10</dc:creator></item><item><title>RE: Slow SP with date parameters solved.</title><link>http://www.sqlservercentral.com/Forums/Topic911108-2685-1.aspx</link><description>I've run across this problem several times as well.I try copying the parameters into local variables, then use the local variables in the WHERE clause. That almost always fixes the problem.The two result in very different execution plans, though I've never really understood why.I'd love to hear what is going on behind the scenes.</description><pubDate>Wed, 28 Apr 2010 07:58:31 GMT</pubDate><dc:creator>christopher.gray</dc:creator></item><item><title>RE: Slow SP with date parameters solved.</title><link>http://www.sqlservercentral.com/Forums/Topic911108-2685-1.aspx</link><description>Not very scientific, but I found that the first time I ran, the result from the @tableparams was considerably faster when selecting approx 17,000 rows from 682,000, where there is no useful index.(17234 row(s) affected)SQL Server Execution Times:   CPU time = 2250 ms,  elapsed time = 8095 ms.-- this one was parameterised(17234 row(s) affected)SQL Server Execution Times:   CPU time = 515 ms,  elapsed time = 1784 ms.-- this using the table variableRunning exactly the same thing a second time the difference was greatly reduced.(17234 row(s) affected)SQL Server Execution Times:   CPU time = 343 ms,  elapsed time = 958 ms.(17234 row(s) affected)SQL Server Execution Times:   CPU time = 314 ms,  elapsed time = 264 ms.Using a different table, the paraemterised query was quicker on the second run.</description><pubDate>Wed, 28 Apr 2010 04:33:37 GMT</pubDate><dc:creator>hillsl</dc:creator></item><item><title>RE: Slow SP with date parameters solved.</title><link>http://www.sqlservercentral.com/Forums/Topic911108-2685-1.aspx</link><description>Starting from sql2000 sp4 and sql2005, sql2008, the optimizer changed strategy to retrieve data when you specify parameters in the where clause. So, in this case "column1 between @from and @to" for the optimizer means "read all rows" and starts with a full scan table instead of using index. Another solution is using hints and force the use of index: select * from tab with(index(idx_tab)) where column1 between @from and @to</description><pubDate>Wed, 28 Apr 2010 01:33:58 GMT</pubDate><dc:creator>Carlo Romagnano</dc:creator></item><item><title>RE: Slow SP with date parameters solved.</title><link>http://www.sqlservercentral.com/Forums/Topic911108-2685-1.aspx</link><description>I checked it on 1030484 rows and in my case it worked the same when I run it from direct query and from a SP</description><pubDate>Wed, 28 Apr 2010 01:22:35 GMT</pubDate><dc:creator>ahaliav</dc:creator></item><item><title>RE: Slow SP with date parameters solved.</title><link>http://www.sqlservercentral.com/Forums/Topic911108-2685-1.aspx</link><description>I don't understand the problem you are trying to solve.Is it a parameterization issue?Ditto previous comment i.e what sql version have you found this to be an issue on?How large were your tables? Were they indexed? Did you look at the execution plan to analyse what was going on?</description><pubDate>Wed, 28 Apr 2010 00:52:36 GMT</pubDate><dc:creator>r5d4</dc:creator></item><item><title>RE: Slow SP with date parameters solved.</title><link>http://www.sqlservercentral.com/Forums/Topic911108-2685-1.aspx</link><description>.</description><pubDate>Wed, 28 Apr 2010 00:46:20 GMT</pubDate><dc:creator>ahaliav</dc:creator></item><item><title>Slow SP with date parameters solved.</title><link>http://www.sqlservercentral.com/Forums/Topic911108-2685-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/Stored+Procedures/70112/"&gt;Slow SP with date parameters solved.&lt;/A&gt;[/B]</description><pubDate>Tue, 27 Apr 2010 07:39:18 GMT</pubDate><dc:creator>Virgilio Licovali Bustos Ramirez</dc:creator></item></channel></rss>