SQLite IIF() Function
Example
Return Yes if 500 is greater than 100:
SELECT IIF(500 > 100, 'Yes', 'No');
Try it Yourself »
Definition and Usage
The IIF() function returns the second argument if the condition is true, and the third argument if it is not.
Note: For more than two choices, use the CASE expression.
Syntax
IIF(condition, value_if_true, value_if_false)
Parameter Values
| Parameter | Description |
|---|---|
| condition | Required. The condition to test |
| value_if_true | Required. The value to return if the condition is true |
| value_if_false | Required. The value to return if the condition is false or NULL |
Technical Details
| Return type: | Same as the returned value |
|---|---|
| Works in: | SQLite 3.32.0 and later |
More Examples
Example
Mark the products as cheap or expensive:
SELECT ProductName, Price,
IIF(Price > 50, 'Expensive', 'Cheap')
FROM Products;
Try it Yourself »