Choose and IIF Function in Sql Server

Choose function in SQL Server is used to get the item at the specified index from the list of available values. The index position starts with 1.

Syntax

Select choose(index,value1,value2,..)

1

If the mentioned index is greater or less than the specified values, It results null.

2

If we pass the float value in the index it will be converted to an integer, based on that the value will be selected.

3

IIF Function

If function returns the one of the two values, depending on the condition evaluates true or false.

Syntax


IIF(BOOLEAN CONDITION,TRUE_VALUE,FALSE_VALUE

The IIF function is like Ternary operator in a programming language with single condition.

4