﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Alex Grinberg / Article Discussions / Article Discussions by Author  / Self Eliminated Parameters / 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>Tue, 21 May 2013 04:30:10 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>That assumes that the Column_Name field doesn't allow null values otherwise, I believe, if the value does happen to be null setting the @Param_Name to null won't "eliminate" it. Null is not equal to Null.</description><pubDate>Tue, 10 Oct 2006 08:38:00 GMT</pubDate><dc:creator>Dave I</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>Maybe that's the difference... I'm running SQL Sever 2000 Enterprise Edition with SP4.  Just kidding... I get the same execution plans on an SP3a box as well.  I don't know what the difference is because I havn't altered Northwind on either of mine either.</description><pubDate>Tue, 10 Oct 2006 06:20:00 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;There's not enough data in northwind as it is to properly test this and you must test this like the author suggested using multiple ( optional ) parameters - testing with one where clause does not fully illustrate the issues, the idea of using this approach, quite correctly and I agree with Alex's solution, is that you wish to typically deal with many parameters , please choose at least 6 for testing, which may or may not be passed thus making multiple procs ( one to match each combination ) or multiple if statements unworkable. Then see how the performance degrades with respect to data size and how difficult it is to index. And don't always just have one matching result per where clause - real life often isn't like that.&lt;/P&gt;&lt;P&gt;btw - good one Alex you've sparked an interesting thread!&lt;/P&gt;</description><pubDate>Tue, 10 Oct 2006 01:22:00 GMT</pubDate><dc:creator>colin.Leversuch-Roberts</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;Fyi, this is my execution plan for the smart filter query:&lt;/P&gt;&lt;P&gt;StmtText                                                                                                                                    -------------------------------------------------------------------------------------------------------------------------------------------   |--Bookmark Lookup(BOOKMARK&lt;img src='images/emotions/sad.gif' height='20' width='20' border='0' title='Sad' align='absmiddle'&gt;[Bmk1000]), OBJECT&lt;img src='images/emotions/sad.gif' height='20' width='20' border='0' title='Sad' align='absmiddle'&gt;[Northwind].[dbo].[Customers]))       |--Index Scan(OBJECT&lt;img src='images/emotions/sad.gif' height='20' width='20' border='0' title='Sad' align='absmiddle'&gt;[Northwind].[dbo].[Customers].[City]),  WHERE&lt;img src='images/emotions/sad.gif' height='20' width='20' border='0' title='Sad' align='absmiddle'&gt;[Customers].[CustomerID]=[@CustomerID] OR [@CustomerID]=NULL))&lt;/P&gt;&lt;P&gt;My Northwind database is unaltered (I never used it until today). I updated the statistics (UPDATE STATISTICS customers WITH FULLSCAN) but I get the same query plan. I'm running SQL 2000 SP3a btw.&lt;/P&gt;</description><pubDate>Mon, 09 Oct 2006 21:45:00 GMT</pubDate><dc:creator>laperrej</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;I ran your code against the Northwind database (assume that's where you were running it, as well)... Just to be sure, this is your code, isn't it (I added the ShowPlan)&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;SET SHOWPLAN_TEXT ONgo&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;DECLARE @CustomerID nchar(5)SET @CustomerID = 'AROUT'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;SELECT *FROM CustomersWHERE (CustomerID = @CustomerID OR @CustomerID IS NULL)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;SELECT *FROM CustomersWHERE CustomerID = @CustomerID&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;When I run it, I get the same thing as when I show the graphical execution plan...&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;StmtText                       ------------------------------ SET STATISTICS PROFILE ON&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;(1 row(s) affected)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;StmtText                ----------------------- SET SHOWPLAN_TEXT ON&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;(1 row(s) affected)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;StmtText                                                                               -------------------------------------------------------------------------------------- &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;DECLARE @CustomerID nchar(5)SET @CustomerID = 'AROUT'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;SELECT *FROM CustomersWHERE (CustomerID = @CustomerID OR @CustomerID IS NULL)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;(2 row(s) affected)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;StmtText                                                                                                                                                -------------------------------------------------------------------------------------------------------------------------------------------------------   |--&lt;STRONG&gt;Clustered Index Scan&lt;/STRONG&gt;(OBJECT&lt;img src='images/emotions/sad.gif' height='20' width='20' border='0' title='Sad' align='absmiddle'&gt;[Northwind].[dbo].[Customers].[PK_Customers]), WHERE&lt;img src='images/emotions/sad.gif' height='20' width='20' border='0' title='Sad' align='absmiddle'&gt;[Customers].[CustomerID]=[@CustomerID] OR [@CustomerID]=NULL))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;(1 row(s) affected)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;StmtText                                                         ---------------------------------------------------------------- &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;SELECT *FROM CustomersWHERE CustomerID = @CustomerID&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;(1 row(s) affected)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;StmtText                                                                                                                                         ------------------------------------------------------------------------------------------------------------------------------------------------   |--&lt;STRONG&gt;Clustered Index Seek&lt;/STRONG&gt;(OBJECT&lt;img src='images/emotions/sad.gif' height='20' width='20' border='0' title='Sad' align='absmiddle'&gt;[Northwind].[dbo].[Customers].[PK_Customers]), SEEK&lt;img src='images/emotions/sad.gif' height='20' width='20' border='0' title='Sad' align='absmiddle'&gt;[Customers].[CustomerID]=[@CustomerID]) ORDERED FORWARD)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;(1 row(s) affected)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;StmtText                      ----------------------------- SET STATISTICS PROFILE OFF&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;(1 row(s) affected)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;No city index... no table scan... I'm thinking that something is wrong with your Northwind Customers table... it must be missing an index or PK or something...&lt;/P&gt;</description><pubDate>Mon, 09 Oct 2006 21:40:00 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>Please look again &lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;. The code I posted does an index scan on the City index. The primary key is CustomerID. The statistics must tell SQL Server that scanning the City index to find CustomerIDs is cheaper than doing a full table scan.</description><pubDate>Mon, 09 Oct 2006 21:24:00 GMT</pubDate><dc:creator>laperrej</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;City Index?  Neither the code you posted or my code would even come near a "city" index if the Primary Key was the CustomerID column. &lt;img src='images/emotions/shocked.gif' height='20' width='20' border='0' title='Shocked' align='absmiddle'&gt;  Certainly, it wouldn't do a table scan if an index were present on CustomerID... Index Scan, yes... table scan, no.&lt;/P&gt;&lt;P&gt;The only reason I made the disclaimer about INT was because I didn't test it using VARCHAR. &lt;img src='images/emotions/biggrin.gif' height='20' width='20' border='0' title='Big Grin' align='absmiddle'&gt;&lt;/P&gt;</description><pubDate>Mon, 09 Oct 2006 20:52:00 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;Note that it has nothing to do with the fact that it's an integer ID btw. Because we're looking for CustomerID, which is the clustered index, and every non-clustered index contains the clustered index column(s) as the last column(s), SQL Server will scan the smallest index, in this case the City index. If CustomerID was a varchar, the execution plan would be just the same.&lt;/P&gt;</description><pubDate>Mon, 09 Oct 2006 20:33:00 GMT</pubDate><dc:creator>laperrej</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;Alex,&lt;/P&gt;&lt;P&gt;Nice article especially for the proverbial "newbie".  I do agree that the examples were a bit overdone but how are ya going to learn if you don't try? &lt;img src='images/emotions/wink.gif' height='20' width='20' border='0' title='Wink' align='absmiddle'&gt;&lt;/P&gt;</description><pubDate>Mon, 09 Oct 2006 19:49:00 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;I've found that that is &lt;STRONG&gt;NOT&lt;/STRONG&gt; true... not with INT ID's anyway... In my testing of the various solutions posted against this article, I get INDEX SCAN's, not table scans using WHERE (CustID = @CustID OR @CustID IS NULL).&lt;/P&gt;&lt;P&gt;In fact, the method advertised is the second fastest method (direct and dynamic SQL tied for first fastest) of those posted and some not posted.  Considering the flexibility of the code and the fact that you don't have to juggle the dynamic SQL code to make it "injection proof", it's not a bad method.&lt;/P&gt;&lt;P&gt;Still, I do like the dynamic SQL because of the blazing speed even if I do have to add a little code to keep Gumby and his brothers out...&lt;/P&gt;&lt;P&gt;&lt;TABLE class=quote cellSpacing=1 cellPadding=5&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD vAlign=top noWrap width=11&gt;&lt;IMG height=13 alt=quote src="http://www.sqlservercentral.com/forums/images/quoteicon.gif" width=11 align=absMiddle&gt;&lt;/TD&gt;&lt;TD width="99%"&gt;&lt;DL&gt;&lt;DT&gt;&lt;SPAN id=Showtread1_ThreadRepeater__ctl9_lblFullMessage&gt;how is this technique all that clever? If anything, using &lt;/SPAN&gt;&lt;/DT&gt;&lt;DT&gt;&lt;SPAN&gt;select *&lt;/DT&gt;&lt;DT&gt;from Customers&lt;/DT&gt;&lt;DT&gt;where customerid=isnull(@customerid,customerId)&lt;/DT&gt;&lt;DT&gt;is more efficient, easier to read and takes up less space.&lt;/DT&gt;&lt;/DL&gt;&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;&lt;P&gt;More efficient?  Like a previous respondent stated, you may want to test the code before making those type of statements.  The "efficient" method you spoke of forces a table scan resulting in a 43 second time of return.  The method Alex wrote about (&lt;A href="mailto:colname=@variable"&gt;colname=@variable&lt;/A&gt; OR @variable IS NULL) only took 453 MILLI-seconds.  That's about 94 times faster give or take a clock cycle.&lt;/P&gt;&lt;P&gt;Here's the code I used on the lowly 1.4 million record Customer table on the Test Server at work... some of the print statements also serve as the documentation for what I found for performance on a quiet server...&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;DECLARE @StartTime DATETIMEDECLARE @CustID INTSET @CustID = 1650&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;  PRINT 'BASELINE... simple direct lookup (0.016 seconds - Index Seek)'   DBCC DROPCLEANBUFFERS   DBCC FREEPROCCACHE    SET @StartTime = GETDATE() SELECT *   FROM dbo.Customer WITH (NOLOCK)  WHERE CustID = @CustID   PRINT DATEDIFF (ms,@StartTime,GETDATE())  PRINT REPLICATE('-',78)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;  PRINT 'Using the technique from the article (0.453 seconds - Index Scan)'   DBCC DROPCLEANBUFFERS   DBCC FREEPROCCACHE    SET @StartTime = GETDATE() SELECT *   FROM dbo.Customer WITH (NOLOCK)  WHERE (CustID = @CustID OR @CustID IS NULL)  PRINT DATEDIFF (ms,@StartTime,GETDATE())  PRINT REPLICATE('-',78)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;  PRINT 'Using dynamic sql (extendable) (0.016 seconds - Index Seek)'   DBCC DROPCLEANBUFFERS   DBCC FREEPROCCACHEDECLARE @SQL VARCHAR(8000)    SET @StartTime = GETDATE()    SET @SQL = '                SELECT *                FROM dbo.Customer WITH (NOLOCK)                WHERE 1=1' + ISNULL(' AND CustID = '+STR(@CUSTID),'')   EXEC (@SQL)  PRINT DATEDIFF (ms,@StartTime,GETDATE())  PRINT REPLICATE('-',78)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;  PRINT 'Using ISNULL (one of the alternatives offered) (43.110 seconds - Table Scan)'   DBCC DROPCLEANBUFFERS   DBCC FREEPROCCACHE    SET @StartTime = GETDATE()  SELECT *   FROM dbo.Customer WITH (NOLOCK)  WHERE CustID = ISNULL(@CustID,CustID) --REAL SLOW!!! TABLE SCAN!!!  PRINT DATEDIFF (ms,@StartTime,GETDATE())  PRINT REPLICATE('-',78)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;  PRINT 'Using semi-static method (42.703 seconds - Table Scan)'   DBCC DROPCLEANBUFFERS   DBCC FREEPROCCACHEDECLARE @IntMin INTDECLARE @IntMax INT    SET @IntMin = -2147483648    SET @IntMax =  2147483647    SET @StartTime = GETDATE()  SELECT *   FROM dbo.Customer WITH (NOLOCK)  WHERE CustID BETWEEN ISNULL(@CustID,@IntMin) AND ISNULL(@CustID,@IntMax)  PRINT DATEDIFF (ms,@StartTime,GETDATE())  PRINT REPLICATE('-',78)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;  PRINT 'Using CASE method (42.610 seconds - Table Scan)'   DBCC DROPCLEANBUFFERS   DBCC FREEPROCCACHE    SET @StartTime = GETDATE()  SELECT *   FROM dbo.Customer WITH (NOLOCK)  WHERE CustID = CASE WHEN @CustID IS NULL THEN CustID ELSE @CustID END  PRINT DATEDIFF (ms,@StartTime,GETDATE())  PRINT REPLICATE('-',78)&lt;/FONT&gt;&lt;/P&gt;</description><pubDate>Mon, 09 Oct 2006 19:39:00 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;Be careful with this one.&lt;/P&gt;&lt;P&gt;we have tables with 6 million rows and doing&lt;/P&gt;&lt;P&gt;WHERE (CustomerName = @CustomerName OR @CustomerName IS NULL)killed perfomance. The query took more than 2 minutes.&lt;/P&gt;&lt;P&gt;User dynamic SQL with EXEC or SP_EXECUTESQL.watch out for single quotes with EXEC, to prevent SQL Injection and to deal with certain last names.O'Malley in SQL is 'O''Malley'IF @CustomerName IS NOT NULLBEGIN    SET @sql = @sql + N' AND CustomerName = ''' + REPLACE(@CustomerName,'''','''''') + ''''END&lt;/P&gt;</description><pubDate>Mon, 09 Oct 2006 18:14:00 GMT</pubDate><dc:creator>roygelerman</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;I do not beleive the author says the solution is clever. It is just offered as a solution to a common problem. Personally, I have used your technique as it works well for our environment. In some circumstances, we have used Dynamic SQL (Prior to learning this technique).&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Overall, the article examples should be simplified for beginners to follow. The technique is valid however.&lt;/P&gt;</description><pubDate>Mon, 09 Oct 2006 10:32:00 GMT</pubDate><dc:creator>cliffb</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>I found the example difficult to follow. To demonstrate the technique you could use one table with one WHERE without XML processing that is not easy for entry-level developers and professional level administrators and without joins. Also there is too much stress on NULL as a defult value. Do not forget that we mostly are in the described situation when users have to select something and they do it through the front end. The developers  often set default value for the dropdown boxes to something meaningful like "please, select the value from the list" or in many cases "All"</description><pubDate>Mon, 09 Oct 2006 09:03:00 GMT</pubDate><dc:creator>Yelena Varshal</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;how is this technique all that clever? If anything, using &lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from Customers&lt;/P&gt;&lt;P&gt;where customerid=isnull(@customerid,customerId)&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;is more efficient, easier to read and takes up less space.&lt;/P&gt;</description><pubDate>Mon, 09 Oct 2006 07:18:00 GMT</pubDate><dc:creator>Bilal Dinc</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>Thanks for the tip, I've come at this problem in the past without any good solutions. For smaller tables, this is perfect!</description><pubDate>Mon, 09 Oct 2006 07:02:00 GMT</pubDate><dc:creator>jwainz</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;Alex - were you aware of another of Erland's excellent articles which discusses just this problem (in a good deal of detail)?&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sommarskog.se/dyn-search.html"&gt;http://www.sommarskog.se/dyn-search.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Mon, 09 Oct 2006 03:53:00 GMT</pubDate><dc:creator>RyanRandall</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;I experimented with this many years ago, if tables are small the benefits are good but on anything else the performance is apalling in terms of i/o and data cache flush. The more optional parameters there are the worse it gets. However, if the proc doesn't get called too often e.g. it's not in an oltp system and you need to avoid dynamic sql because of the security issues and views don't do much then I agree it's a good solution. &lt;/P&gt;&lt;P&gt;From my view in performance tuning developers usually find this and use it without testing on higher numbers of rows ( I won't say large table as it's all relative )  - so it works fine in test - in production tables get into double figure thousands of rows ( or worse ) and suddenly you're looking at a simple proc which is doing very high i/o to return ( usually ) 1 row. So basically what I'd say is this solution is good but it doesn't scale, so use with care.&lt;/P&gt;&lt;P&gt;I'm not having a pop here Alex btw .. but this illustrates that you should test with execution plans when developing code solutions and remember to scale up and out as part of testing.&lt;/P&gt;&lt;P&gt;I hope we don't get into another one of these silly dynamic sql arguments either!!&lt;/P&gt;</description><pubDate>Mon, 09 Oct 2006 03:17:00 GMT</pubDate><dc:creator>colin.Leversuch-Roberts</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>Or the use of the SQL standard COALESCE. Example:WHERE Column_Name=COALESCE(@Param_Name, Column_Name)</description><pubDate>Mon, 09 Oct 2006 02:10:00 GMT</pubDate><dc:creator>Josep</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;If NULL is the default value used, the following construct can also be used:&lt;/P&gt;&lt;P&gt;WHERE (Column_Name = ISNULL(@Param_Name, Column_Name))&lt;/P&gt;</description><pubDate>Mon, 09 Oct 2006 00:27:00 GMT</pubDate><dc:creator>Michiel Rens</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;Another way i commonly use is an extension on the above&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;WHERE((@customerid is not null and customerid = @customerid) or @customerid is null)&lt;/P&gt;</description><pubDate>Sun, 08 Oct 2006 23:49:00 GMT</pubDate><dc:creator>Thomas James</dc:creator></item><item><title>RE: Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>&lt;P&gt;This technique, although interesting, should be used sparingly as it affects performance. The optimizer will perform full table scans on all tables that have a smart filter on them. Therefore, I believe this technique is only acceptable if you're expecting your query to need full table scans anyway. Switch on Execution Plan viewing and inspect the execution plans for the SQL below. The SELECT with the smart filter will always read the entire Customers table, the SELECT you would normally arrive at doing it the conventional way (by building up your SQL according to the filter values that were not null or not the default value) will use a clustered index seek.&lt;/P&gt;&lt;P&gt;DECLARE @CustomerID nchar(5)SET @CustomerID = 'AROUT'&lt;/P&gt;&lt;P&gt;SELECT *FROM CustomersWHERE (CustomerID = @CustomerID OR @CustomerID IS NULL)&lt;/P&gt;&lt;P&gt;SELECT *FROM CustomersWHERE CustomerID = @CustomerID&lt;/P&gt;</description><pubDate>Sun, 08 Oct 2006 20:57:00 GMT</pubDate><dc:creator>laperrej</dc:creator></item><item><title>Self Eliminated Parameters</title><link>http://www.sqlservercentral.com/Forums/Topic312755-229-1.aspx</link><description>Comments posted here are about the content posted at &lt;A HREF="temp"&gt;temp&lt;/A&gt;</description><pubDate>Mon, 02 Oct 2006 14:29:00 GMT</pubDate><dc:creator>Alex Grinberg-230981</dc:creator></item></channel></rss>