If(conditional1, result1, condition2, result2, …, conditionalN, resultN, else-result)

This function checks multiple conditions and returns the corresponding result for the first one that is true; otherwise, the else-result is returned.

Parameters

condition
All conditions must be of type Boolean.
result
The column, expression, or literal value. Must all be of the same type as result1.
else-result
The column, expression, or literal value. Must be of the same type as result1. If omitted, it is assumed to be null.

Returns

The return type is defined by result1.

Remarks

The If function may contain an unlimited number of condition-result pairs. All the conditions will be verified one by one until one of them is found true. The else-result defines what statement should be executed if none of the specified conditions are true.

Examples

Next: In