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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.