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 Execute the Cursor Queries with "OPEN" Statements? |
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | How To Create a View on an Existing Table in MS SQL Server? |
☺ | What Are the Advantages of Passing Name-Value Pairs as Parameters? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |