CHAPTER 3

image

Working with NULLS

by Wayne Sheffield

A NULL value represents the absence of data or, in other words, data that is missing or unknown. When coding queries, stored procedures, or any other T-SQL, it is important to keep in mind the nullability of data because it will affect many aspects of your logic. For example, the default result of most operators (such as, +, -, AND, and OR) is NULL when either operand is NULL.

  • NULL + 10 = NULL
  • NULL AND TRUE = NULL
  • NULL OR FALSE = NULL

The exception occurs when using the OR operator in a NULL OR TRUE test. Since one side of the equation is TRUE, the OR operator will return TRUE even if the other ...

Get SQL Server T-SQL Recipes, Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.