Oracle Consulting Oracle Training Oracle Support Development
Oracle Books
SQL Server Books
IT Books
Job Interview Books
Rampant Horse Books
911 Series
Pedagogue Books

Oracle Software
Write for Rampant
Publish with Rampant
Rampant News
Rampant Authors
Rampant Staff
Oracle News
Oracle Forum
Oracle Tips
Articles by our Authors
Press Releases
SQL Server Books

Oracle 11g Books

Oracle tuning

Oracle training

Oracle support

Remote Oracle


Privacy Policy


  SQL Server Tips by Burleson

About NULL in TSQL

Some programming languages use the = operator to compare expressions with a NULL value. This is legal in TSQL only when the SET option ANSI_NULLS is OFF, but it is ON by default. This happens because of the compliance with the SQL-92 standard, which requires that a comparison against a NULL value always evaluates to FALSE (even if both expressions are NULL). It is important to be aware of how NULL behaves in TSQL when using XP’s because: variables in TSQL have NULL as a default value. This must be taken into consideration when reading parameters values from variables. XP’s might return NULL to a parameter variable that would be used afterwards in a TSQL statement. Unexpected results will occur if the NULL value is not handled properly.

This is an example of using ANSI_NULLS:

declare @b int
SET @b=1
if @b <> NULL PRINT 1
if @b != NULL PRINT 2
if @b = NULL PRINT 3
SET @b=1
if @b <> NULL PRINT 4
if @b != NULL PRINT 5
if @b = NULL PRINT 6

The output will be:

It is recommended to use the IS operator because it is SQL-92 compliant, making the code more portable. SET ANSI_NULLS permissions affect all users and this is an issue because some users might want to develop SQL-92 compliant code.

The above book excerpt is from:

Super SQL Server Systems
Turbocharge Database Performance with C++ External Procedures

ISBN: 0-9761573-2-2
Joseph Gama, P. J. Naughter  

Linux Oracle commands syntax poster

ION Oracle tuning software

Oracle data dictionary reference poster

Oracle Forum

BC Oracle consulting support training

BC remote Oracle DBA   



 Copyright © 1996 -2017 by Burleson. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation. SQL Server® is the registered trademark of Microsoft Corporation. 
Many of the designations used by computer vendors to distinguish their products are claimed as Trademarks

Hit Counter