IFNULL

Returns a result if the input is null, otherwise, returns the input.

Sample usage

IFNULL(Discount, 0)

Syntax

IFNULL(input_expression, null_result)

Parameters

input_expression

The expression to evaluate. You can use any valid expression as the input_expression.

null_result

The result to return if input_expression is null.  If input_expression is not null, IFNULL returns the input_expression. You can use any valid expression as the input_expression.

Example

Suppose you want to calculate the average discount given to your customers, including orders that received no discount, and you know that your application sometimes represents "no discount" as null rather than 0.

The formula AVG(Discount) won't include null discounts. You'll need to convert those nulls to zero. To do this, create a new field called, for example, Discount No Nulls:

IFNULL(Discount, 0)

This formula can be read, "If the Discount field is null, return 0, otherwise return Discount."

You can then calculate the average discount including orders with no discount:

AVG(Discount No Nulls)
Was this helpful?
How can we improve it?
true
Search
Clear search
Close search
Google apps
Main menu
Search Help Center
true
102097
false