> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# IFF

> Returns one of two values according to a Boolean condition.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

A NULL condition selects false\_value. A NULL selected branch produces NULL.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
iff(condition, true_value, false_value)
```

* All result alternatives must have compatible types. Matching types are preserved; mixed types may be converted to a common type. Use explicit casts to choose the result type.

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| condition | BOOLEAN | Yes | Condition to evaluate. |
| true\_value | BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT | Yes | Value selected when the condition is TRUE. Must convert to the same SQL type as the other arguments in this comparison or result branch. Use explicit CAST when mixing types. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). |
| false\_value | BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT | Yes | Value selected when the condition is FALSE or NULL. Must convert to the same SQL type as the other arguments in this comparison or result branch. Use explicit CAST when mixing types. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). |

## Returns

* Type: Common SQL type after conversion of true\_value and false\_value
* NULL behavior: A NULL condition selects false\_value. A NULL selected branch produces NULL.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Partial (Selection is exact; implicit conversions of branch values can alter their representation.) |

## Usage notes

* The two result branches must have compatible types. They are converted to a common type when needed.
* INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
* Query tools may report a DECIMAL result as DOUBLE or a TIME result as INTEGER. The returned value still keeps its decimal precision and scale, or its time type. A reported type does not convert the value.
* Deterministic: The same inputs and settings produce the same result.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT iff(TRUE, 1, 2) AS "value", iff(CAST(NULL AS BOOLEAN), 1, 2) AS null_condition;
```

| value | null\_condition |
| - | - |
| 1 | 2 |

### Choose between string results

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT iff(2 > 1, 'yes', 'no') AS true_branch, iff(2 < 1, 'yes', 'no') AS false_branch;
```

| true\_branch | false\_branch |
| - | - |
| yes | no |

## Related functions

* [coalesce](/query/sql/functions/conditional/coalesce)
* [nvl2](/query/sql/functions/conditional/nvl2)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.