## ANSI NULLS

 Author Message cengland0 SSCommitted Group: General Forum Members Points: 1678 Visits: 1300 Comments posted to this topic are about the item ANSI NULLS TomThomson SSChampion Group: General Forum Members Points: 14292 Visits: 12197 Thanks for the question Tom Nakul Vachhrajani SSCrazy Group: General Forum Members Points: 2252 Visits: 2145 Indeed. Thanks for the question.Word of caution for everyone:Per the MSDN article referred in the answer (http://msdn.microsoft.com/en-us/library/ms188048.aspx), 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. Thanks & Regards,Nakul Vachhrajani.http://nakulvachhrajani.comBe courteous. Drive responsibly.Follow me on Twitter: @sqltwinsGoogle Plus: +Nakul Hardy21 SSCommitted Group: General Forum Members Points: 1580 Visits: 1399 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? Thanks Hugo Kornelis SSChampion Group: General Forum Members Points: 10994 Visits: 11989 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 defines 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:`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`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.) Hugo Kornelis, SQL Server MVPVisit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis Hugo Kornelis SSChampion Group: General Forum Members Points: 10994 Visits: 11989 Hardy21 (10/11/2010)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?Standardisation.ANSI is a standard among relational database implementations. Though it does help in the competition to offer extra 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. Hugo Kornelis, SQL Server MVPVisit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis Carlo Romagnano SSCarpal Tunnel Group: General Forum Members Points: 4915 Visits: 3326 Using SQL Server 2005, what is the output of the SELECT statement below?Same behavior for previous versions of sqlserver. I run on tuttopodismo Daniel Bowlin SSCarpal Tunnel Group: General Forum Members Points: 4092 Visits: 2629 Good question, thanks. Nice additional explanation in the forum. UMG Developer SSCrazy Group: General Forum Members Points: 2684 Visits: 2204 Thanks for the question. SQLRNNR SSC-Dedicated Group: General Forum Members Points: 32286 Visits: 18552 Thanks for the question Jason AKA CirqueDeSQLeilI have given a name to my pain...MCM SQL Server, MVPSQL RNNRPosting Performance Based Questions - Gail Shaw