IFNULL Function [Miscellaneous]

Returns the first nonnull expression, or NULL.

If the first expression is the NULL value, then the value of the second expression is returned. If the first expression is not NULL, the value of the third expression is returned. If the first expression is not NULL and there is no third expression, then the NULL value is returned.

Syntax

IFNULLexpression1, expression2 [ , expression3 ] )

Parameters

Parameters

Parameter

Description

expression1

The expression to be evaluated. Its value determines whether expression2 or expression3 is returned.

expression2

The return value if expression1 is NULL

expression3

The return value if expression1 is not NULL.

Returns

The data type returned depends on the data type of expression-2 and expression-3.

Examples

The following statement returns the value -66:

SELECT IFNULL( NULL, -66 ) FROM iq_dummy

The following statement returns NULL, because the first expression is not NULL and there is no third expression:

SELECT IFNULL( -66, -66 ) FROM iq_dummy

Standards and compatibility

  • SQL—Transact-SQL extension to ISO/ANSI SQL grammar.

  • Sybase—Not supported by Adaptive Server Enterprise.