# Conditional Functions

## CASE

`CASE WHEN <condition1> THEN <return1> [...] [ELSE <else>] END`

**Description**

Find values that match \<condition>  and return the corresponding value.  \<condition> must be a boolean expression (ex: age>20)

**Example**

```
CASE WHEN age < 20 THEN "teenager"
```

```
           WHEN age < 60 THEN "adult"
```

```
           ELSE "elder adult"
```

```
END
```

## IF

`IF(condition, true_result, else_result)`

**Description**

Check whether a value meets a condition and assign it to different values. If TRUE, it returns true\_value. Otherwise, it returns else\_value.

**Example**

```
IF(age > 20, "adult", "nonadult")
```

```
IF(close_price > open_price, "higher", "lower")
```

## IFNULL

`IFNULL(value, null_replacement)`

**Description**

Check whether a value is NULL. If the value is not null, it returns the original value. Otherwise, it returns null\_replacement.

**Example**

```
IFNULL(NULL, -1)
```

Result: -1

```
IFNULL(profit, 0)
```

## NULLIF

`NULLIF(value1, value2)`

**Description**

Check whether value1 is equal to value2. Returns NULL if TRUE, otherwise returns the value1.

**Example**

```
NULLIF(0, 0)
```

Result: NULL

```
NULLIF(10, 0)
```

Result: 10


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.acho.io/acho-studio/data-prep-projects/applying-actions/tools/sql-editor/supported-math-functions-in-formula/conditional-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
