<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://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>Dr. Unknown, or how I learned to stop worrying and love the NULL</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/22/dr-unknown-or-how-i-learned-to-stop-worrying-and-love-the-null.aspx</link><description>Two months ago, I posted the first two parts of a series about NULL. After that, I went quiet. Much to do and little time was one excuse. But to be honest, I also lost interest. However, I felt I owe my readers to conclude the series, so I have now forced</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: Dr. Unknown, or how I learned to stop worrying and love the NULL</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/22/dr-unknown-or-how-i-learned-to-stop-worrying-and-love-the-null.aspx#2651</link><pubDate>Sat, 22 Sep 2007 21:09:08 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2651</guid><dc:creator>Denis Gobo</dc:creator><description>&lt;p&gt;Great article, another reason not to use IN is when you fat-finger the column name&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;p&gt;CREATE TABLE TestTable1 (id1 int) &lt;/p&gt;
&lt;p&gt;CREATE TABLE TestTable2 (id2 int) &lt;/p&gt;
&lt;p&gt;INSERT TestTable1 VALUES(1) &lt;/p&gt;
&lt;p&gt;INSERT TestTable1 VALUES(2) &lt;/p&gt;
&lt;p&gt;INSERT TestTable1 VALUES(3) &lt;/p&gt;
&lt;p&gt;INSERT TestTable2 VALUES(1) &lt;/p&gt;
&lt;p&gt;INSERT TestTable2 VALUES(2) &lt;/p&gt;
&lt;p&gt;SELECT * &lt;/p&gt;
&lt;p&gt;FROM TestTable1 &lt;/p&gt;
&lt;p&gt;WHERE id1 IN (SELECT id1 FROM TestTable2) &lt;/p&gt;
&lt;p&gt;It doesn't matter that the TestTable2 doesn't have a id1 column, all rows will be returned&lt;/p&gt;
&lt;p&gt;Exist is the way to go&lt;/p&gt;
&lt;p&gt;SELECT * &lt;/p&gt;
&lt;p&gt;FROM t1 &lt;/p&gt;
&lt;p&gt;WHERE EXISTS (SELECT * FROM TestTable2 t2 WHERE t2.id2 = t1.id1 ) &lt;/p&gt;
&lt;p&gt;or a join&lt;/p&gt;
&lt;p&gt;SELECT t1.* &lt;/p&gt;
&lt;p&gt;FROM TestTable1 t1 &lt;/p&gt;
&lt;p&gt;JOIN TestTable2 t2 ON t2.id2 = t1.id1 &lt;/p&gt;
</description></item><item><title>re: Dr. Unknown, or how I learned to stop worrying and love the NULL</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/22/dr-unknown-or-how-i-learned-to-stop-worrying-and-love-the-null.aspx#2652</link><pubDate>Sat, 22 Sep 2007 22:17:08 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2652</guid><dc:creator>Hugo Kornelis</dc:creator><description>&lt;p&gt;Good point, Denis!&lt;/p&gt;
&lt;p&gt;This also shows why you should always prefix all column names with the table name (or alias) in a query that touches more than one table.&lt;/p&gt;
&lt;p&gt;BTW, the JOIN solution is only equivalent if TestTable2.id2 is constrained to be UNIQUE or PRIMARY KEY, otherwise it might generate duplicate rows that the other queries don't produce.&lt;/p&gt;
</description></item><item><title>re: Dr. Unknown, or how I learned to stop worrying and love the NULL</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/22/dr-unknown-or-how-i-learned-to-stop-worrying-and-love-the-null.aspx#2662</link><pubDate>Mon, 24 Sep 2007 12:13:39 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2662</guid><dc:creator>James Luetkehoelter</dc:creator><description>&lt;p&gt;Any excellent post Hugo - ironically I was just about to post my next NULL post (hmm...that would make a good April Fool's joke...gotta remember that).&lt;/p&gt;
</description></item><item><title>re: Dr. Unknown, or how I learned to stop worrying and love the NULL</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/22/dr-unknown-or-how-i-learned-to-stop-worrying-and-love-the-null.aspx#2663</link><pubDate>Mon, 24 Sep 2007 12:13:58 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2663</guid><dc:creator>James Luetkehoelter</dc:creator><description>&lt;p&gt;er, another, not any :)&lt;/p&gt;
</description></item><item><title>re: Dr. Unknown, or how I learned to stop worrying and love the NULL</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/22/dr-unknown-or-how-i-learned-to-stop-worrying-and-love-the-null.aspx#2667</link><pubDate>Mon, 24 Sep 2007 20:09:09 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2667</guid><dc:creator>Michael Lato</dc:creator><description>&lt;p&gt;Further to your UNIQUE constraint note above, I have just spoken with some Microsoft techs at the PASS conference about precisely the same request (allow multiple NULL values in a UNQUE constraint). &amp;nbsp;SQL Server 2008 will allow filtered indexes and the UNIQUE keyword is valid. &amp;nbsp;You can test this in the July CTP.&lt;/p&gt;
</description></item><item><title>re: Dr. Unknown, or how I learned to stop worrying and love the NULL</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/22/dr-unknown-or-how-i-learned-to-stop-worrying-and-love-the-null.aspx#2758</link><pubDate>Sun, 30 Sep 2007 20:29:56 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2758</guid><dc:creator>Hugo Kornelis</dc:creator><description>&lt;p&gt;Hi Michael,&lt;/p&gt;
&lt;p&gt;Good to know that there will be some way available to us to allow multiple NULLs in a UNIQUE constraint - though I still think that this should be the default behaviour of UNIQUE constraint, as per ANSI standard.&lt;/p&gt;
&lt;p&gt;But if I can't have full ANSI compatibility, I'll grab this with all might! &amp;lt;g&amp;gt;&lt;/p&gt;
</description></item><item><title>re: Dr. Unknown, or how I learned to stop worrying and love the NULL</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/22/dr-unknown-or-how-i-learned-to-stop-worrying-and-love-the-null.aspx#2765</link><pubDate>Mon, 01 Oct 2007 06:17:46 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2765</guid><dc:creator>Hugo Kornelis</dc:creator><description>&lt;p&gt;The fourth (and final) part of this series about &amp;nbsp;NULL is now available at &lt;a rel="nofollow" target="_new" href="http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/30/what-if-null-if-null-is-null-null-null-is-null.aspx"&gt;http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/30/what-if-null-if-null-is-null-null-null-is-null.aspx&lt;/a&gt;.&lt;/p&gt;
</description></item><item><title>re: Dr. Unknown, or how I learned to stop worrying and love the NULL</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/22/dr-unknown-or-how-i-learned-to-stop-worrying-and-love-the-null.aspx#2853</link><pubDate>Wed, 03 Oct 2007 13:42:47 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2853</guid><dc:creator>ScottPletcher</dc:creator><description>&lt;p&gt;Great article! &amp;nbsp;Informative and thought provoking. &amp;nbsp;Btw, within the last day I helped someone on Experts-Exchange who had indeed used a NULL in a NOT IN list, so it does happen :-) .&lt;/p&gt;
</description></item><item><title>The Sad State Of Programmers Part 2 : The In Person Interview</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/22/dr-unknown-or-how-i-learned-to-stop-worrying-and-love-the-null.aspx#3815</link><pubDate>Mon, 10 Dec 2007 20:02:13 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:3815</guid><dc:creator>Denis Gobo</dc:creator><description>&lt;p&gt;This is part two of a three part series. Part one was about the phone interview , this part is about&lt;/p&gt;
</description></item><item><title>re: Dr. Unknown, or how I learned to stop worrying and love the NULL</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/22/dr-unknown-or-how-i-learned-to-stop-worrying-and-love-the-null.aspx#6123</link><pubDate>Tue, 08 Apr 2008 10:12:53 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:6123</guid><dc:creator>phil</dc:creator><description>&lt;p&gt;excellent post, you really saved my bacon trying to solve a select where name = @name (but if not specified) select all 'name' values &amp;nbsp;including nulls :)... &amp;nbsp;WHERE (ProductCategoryId = @ProductCategoryId)&lt;/p&gt;
&lt;p&gt;OR (ProductCategoryId IS NULL AND @ProductCategoryId IS NULL)&lt;/p&gt;
&lt;p&gt;OR (ProductCategoryId IS NOT NULL AND @ProductCategoryId IS NULL)&lt;/p&gt;
</description></item></channel></rss>