Microsoft SQL Server ISNULL()


Example

The IsNull() function accepts two parameters, and returns the second parameter if the first one is null.

Parameters:

  1. check expression. Any expression of any data type.
  2. replacement value. This is the value that would be returned if the check expression is null. The replacement value must be of a data type that can be implicitly converted to the data type of the check expression.

The IsNull() function returns the same data type as the check expression.

DECLARE @MyInt int -- All variables are null until they are set with values.

SELECT ISNULL(@MyInt, 3) -- Returns 3.

See also COALESCE, above