﻿<?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 Cary England  / ANSI NULLS / 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>Wed, 22 May 2013 23:08:46 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: ANSI NULLS</title><link>http://www.sqlservercentral.com/Forums/Topic1001761-2809-1.aspx</link><description>Thanks for your explanation[quote][b]Hugo Kornelis (10/11/2010)[/b][hr]Great question. Thanks, cengland.In addition to the explanation: "Thorough testing shows this also applies to the IN statement", there is also a logical explanation.The ANSI standard [i]defines[/i] the IN operator as a series of OR'ed equation tests. In other word, the ANSI standard says that "x IN (a, b, c)" equates to "x = a OR x = b OR x = c". Or in the case of this question, "WHERE Column1 IN (1,NULL)" equates to "WHERE Column1 = 1 OR Column1 = NULL". Under ANSI null setting, any comparison to NULL always results in the truth value Unknown. So for the five rows in the sample table, here are the evaluation results:[code]Column1 | Column1 = 1 | Column1 = NULL | Column1 = 1 OR Column1 = NULL--------+-------------+----------------+------------------------------ 1      | True        | Unknown        | True 2      | False       | Unknown        | Unknown 3      | False       | Unknown        | Unknown 4      | False       | Unknown        | Unknown Null   | Unknown     | Unknown        | Unknown[/code]Only rows where the condition evaluates to True will be returned, so that is only 1 row.With ANSI NULLS OFF, the result of a NULL = NULL test changes to True, so the last line now changes to all True results. (I don't know if the result of a (not NULL) = NULL test changes to False under non-ANSI settings. I've never used them and since they are deprecated, I don't really care.)[/quote]</description><pubDate>Tue, 19 Oct 2010 22:58:18 GMT</pubDate><dc:creator>sharath.chalamgari</dc:creator></item><item><title>RE: ANSI NULLS</title><link>http://www.sqlservercentral.com/Forums/Topic1001761-2809-1.aspx</link><description>Thanks for the question</description><pubDate>Mon, 18 Oct 2010 10:19:18 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: ANSI NULLS</title><link>http://www.sqlservercentral.com/Forums/Topic1001761-2809-1.aspx</link><description>Thanks for the question.</description><pubDate>Mon, 11 Oct 2010 11:40:41 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RE: ANSI NULLS</title><link>http://www.sqlservercentral.com/Forums/Topic1001761-2809-1.aspx</link><description>Good question, thanks.  Nice additional explanation in the forum.</description><pubDate>Mon, 11 Oct 2010 05:49:48 GMT</pubDate><dc:creator>Daniel Bowlin</dc:creator></item><item><title>RE: ANSI NULLS</title><link>http://www.sqlservercentral.com/Forums/Topic1001761-2809-1.aspx</link><description>[quote]Using SQL Server 2005, what is the output of the SELECT statement below?[/quote]Same behavior for previous versions of sqlserver.</description><pubDate>Mon, 11 Oct 2010 03:43:57 GMT</pubDate><dc:creator>Carlo Romagnano</dc:creator></item><item><title>RE: ANSI NULLS</title><link>http://www.sqlservercentral.com/Forums/Topic1001761-2809-1.aspx</link><description>[quote][b]Hardy21 (10/11/2010)[/b][hr]Nice question.I think the reason for 'ANSI_NULLS will always be ON' for future version is to make the application behavior consistent.Any other reason?[/quote]Standardisation.ANSI is a standard among relational database implementations. Though it does help in the competition to offer [i]extra[/i] features in addition to the standard, it does not help to have features that go against the standard. Complete portability will always be an illusion, but the less code changes are required to port from one DBMS to another, the more pleased some customers are.I think the only reason SET ANSI_NULLS OFF was introduced was to preserve backward compatibility with behaviour of very old implementations that predate the official standard. However, this is just speculation.</description><pubDate>Mon, 11 Oct 2010 03:20:55 GMT</pubDate><dc:creator>Hugo Kornelis</dc:creator></item><item><title>RE: ANSI NULLS</title><link>http://www.sqlservercentral.com/Forums/Topic1001761-2809-1.aspx</link><description>Great question. Thanks, cengland.In addition to the explanation: "Thorough testing shows this also applies to the IN statement", there is also a logical explanation.The ANSI standard [i]defines[/i] the IN operator as a series of OR'ed equation tests. In other word, the ANSI standard says that "x IN (a, b, c)" equates to "x = a OR x = b OR x = c". Or in the case of this question, "WHERE Column1 IN (1,NULL)" equates to "WHERE Column1 = 1 OR Column1 = NULL". Under ANSI null setting, any comparison to NULL always results in the truth value Unknown. So for the five rows in the sample table, here are the evaluation results:[code]Column1 | Column1 = 1 | Column1 = NULL | Column1 = 1 OR Column1 = NULL--------+-------------+----------------+------------------------------ 1      | True        | Unknown        | True 2      | False       | Unknown        | Unknown 3      | False       | Unknown        | Unknown 4      | False       | Unknown        | Unknown Null   | Unknown     | Unknown        | Unknown[/code]Only rows where the condition evaluates to True will be returned, so that is only 1 row.With ANSI NULLS OFF, the result of a NULL = NULL test changes to True, so the last line now changes to all True results. (I don't know if the result of a (not NULL) = NULL test changes to False under non-ANSI settings. I've never used them and since they are deprecated, I don't really care.)</description><pubDate>Mon, 11 Oct 2010 03:17:40 GMT</pubDate><dc:creator>Hugo Kornelis</dc:creator></item><item><title>RE: ANSI NULLS</title><link>http://www.sqlservercentral.com/Forums/Topic1001761-2809-1.aspx</link><description>Nice question.I think the reason for 'ANSI_NULLS will always be ON' for future version is to make the application behavior consistent.Any other reason?</description><pubDate>Mon, 11 Oct 2010 02:15:25 GMT</pubDate><dc:creator>Hardy21</dc:creator></item><item><title>RE: ANSI NULLS</title><link>http://www.sqlservercentral.com/Forums/Topic1001761-2809-1.aspx</link><description>Indeed. Thanks for the question.[b]Word of caution for everyone:[/b]Per the MSDN article referred in the answer ([url]http://msdn.microsoft.com/en-us/library/ms188048.aspx[/url]), ANSI_NULLS will always be ON in a future version of SQL Server. If developing any new application, please take this important consideration as part of your design. For pre-existing applications, please work towards re-engineering them if they are using ANSI_NULLS OFF.Edited to add the MSDN article URL.</description><pubDate>Mon, 11 Oct 2010 02:00:03 GMT</pubDate><dc:creator>Nakul Vachhrajani</dc:creator></item><item><title>RE: ANSI NULLS</title><link>http://www.sqlservercentral.com/Forums/Topic1001761-2809-1.aspx</link><description>Thanks for the question</description><pubDate>Sun, 10 Oct 2010 04:30:08 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>ANSI NULLS</title><link>http://www.sqlservercentral.com/Forums/Topic1001761-2809-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/70954/"&gt;ANSI NULLS&lt;/A&gt;[/B]</description><pubDate>Sat, 09 Oct 2010 17:13:37 GMT</pubDate><dc:creator>cengland0</dc:creator></item></channel></rss>