SQLite iif() Function

The SQLite iif() function has 3 parameters, if the first parameter is true, it returns the second parameter, otherwise it returns the third parameter.

Syntax

Here is the syntax of the SQLite iif() function:

iif(expr1, expr2, expr3)

Parameters

expr1

Required. A value or expression to check if it is true.

expr2

Required. A value or expression.

expr3

Required. Another value or expression.

Return value

If expr1 is true, the SQLite iif() function returns expr2, otherwise it returns expr3.

Examples

This example shows the basic usage of the SQLite ifnull() function:

SELECT
    iif(true, 1, 0),
    iif(false, 1, 0);
 iif(true, 1, 0) = 1
iif(false, 1, 0) = 0

Alternatively, you can pass an expression to the first parameter:

SELECT
    iif(1 = 1, 1, 0),
    iif(1 = 0, 1, 0);
iif(1 = 1, 1, 0) = 1
iif(1 = 0, 1, 0) = 0