Handling NULL

Learn how to handle NULL values in T-SQL.

Sometimes a row or an object will not contain any value (NULL), and we must handle such cases properly. For example, we might want to check whether a value is NULL and replace it with another value. T-SQL provides ISNULL() and COALESCE() methods for this purpose.

The ISNULL() function

This function checks whether a value is NULL. If it is NULL, then the function returns the value that is passed as the second parameter. Otherwise, the function returns the first value:

ISNULL([Value to check], [Value to return if NULL])

Let’s consider the following Profiles table.

Get hands-on with 1200+ tech skills courses.