Home >> FAQs/Tutorials >> SQL Server FAQ

SQL Server FAQ - NULL Values Involved in Boolean Operations

By: FYIcenter.com

(Continued from previous topic...)

What Happens If NULL Values Are Involved in Boolean Operations?

If 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:

AND     TRUE    FALSE   NULL
TRUE    true    false   null
FALSE   false   false   false
NULL    null    false   null

For OR operator, TRUE takes precedence over NULL. The result can be summarized in a table below:

OR      TRUE    FALSE   NULL
TRUE    true    true    true
FALSE   true    false   null
NULL    true    null    null

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

(Continued on next topic...)

  1. What Are NULL Values?
  2. How To Assign NULL Values to Variables or Columns?
  3. What Happens If NULL Values Are Involved in Arithmetic Operations?
  4. What Happens If NULL Values Are Involved in String Operations?
  5. What Happens If NULL Values Are Involved in Datetime Operations?
  6. What Happens If NULL Values Are Involved in Bitwise Operations?
  7. What Happens If NULL Values Are Involved in Comparison Operations?
  8. What Happens If NULL Values Are Involved in Boolean Operations?
  9. How To Test NULL Values Properly?
  10. How To Replace NULL Values in Expressions using ISNULL()?
  11. How To Replace Given Values with NULL using NULLIF()?

Related Articles:

More...


Other Tutorials/FAQs:

More...


Related Resources:

More...


Selected Jobs:

More...