What Happens If NULL Values Are Involved in Boolean Operations?
Submitted by: AdministratorIf NULL values are involved in Boolean operations, the result will vary depending on the operator type. For AND operator, FALSE takes precedence over NULL. The result can be summarized in a table below:
<pre>AND TRUE FALSE NULL
TRUE true false null
FALSE false false false
NULL null false null</pre>
For OR operator, TRUE takes precedence over NULL. The result can be summarized in a table below:
<pre>OR TRUE FALSE NULL
TRUE true true true
FALSE true false null
NULL true null null</pre>
The tutorial script below shows you that NULL AND FALSE returns FALSE:
IF 0=NULL AND 0=1 PRINT 'NULL AND FALSE returns TRUE'
ELSE PRINT 'NULL AND FALSE does not returns TRUE'
GO
NULL AND FALSE does not returns TRUE
IF NOT (0=NULL AND 0=1)
PRINT 'NULL AND FALSE returns FALSE'
ELSE PRINT 'NULL AND FALSE does not returns FALSE'
GO
NULL AND FALSE returns FALSE
Submitted by: Administrator
<pre>AND TRUE FALSE NULL
TRUE true false null
FALSE false false false
NULL null false null</pre>
For OR operator, TRUE takes precedence over NULL. The result can be summarized in a table below:
<pre>OR TRUE FALSE NULL
TRUE true true true
FALSE true false null
NULL true null null</pre>
The tutorial script below shows you that NULL AND FALSE returns FALSE:
IF 0=NULL AND 0=1 PRINT 'NULL AND FALSE returns TRUE'
ELSE PRINT 'NULL AND FALSE does not returns TRUE'
GO
NULL AND FALSE does not returns TRUE
IF NOT (0=NULL AND 0=1)
PRINT 'NULL AND FALSE returns FALSE'
ELSE PRINT 'NULL AND FALSE does not returns FALSE'
GO
NULL AND FALSE returns FALSE
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | How To Use Subqueries with the EXISTS Operators in MS SQL Server? |
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | How To Convert a Numeric Expression from One Data Type to Another? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
☺ | What Are the Character String Functions Supported by SQL Server 2005? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Sybase Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |