CHOOSE
Function
Returns one of the arguments, as specified by numeric index in the first argument.
Syntax
CHOOSE(index, value1, value2, [value3], ...)
Parameters
- index: integer
A 1-based index into the list of values to follow. - value1, value2, value3, ...: scalar
The values to choose from.
Return Value
If index is between 1 and the number of value arguments, then the corresponding value argument is returned. If the index is out of bounds,NULL
is returned.Example
PRINT CHOOSE(1, 'A', 'B'); -- "A"
DECLARE @x = CHOOSE(5, 111, 222);
IF @x IS NULL
PRINT 'Out of range!' -- Prints.