5 out of 10 rated this helpful - Rate this topic

CHOOSE (Transact-SQL)

Returns the item at the specified index from a list of values.

Topic link icon Transact-SQL Syntax Conventions


          

CHOOSE ( index, val_1, val_2 [, val_n ] )
        
index

Is an integer expression that represents a 1-based index into the list of the items following it.

If the provided index value has a numeric data type other than int, then the value is implicitly converted to an integer. If the index value exceeds the bounds of the array of values, then CHOOSE returns null.

val_1 … val_n

List of values of any data type.

Returns the data type with the highest precedence from the set of types passed to the function. For more information, see Data Type Precedence (Transact-SQL).

CHOOSE acts like an index into an array, where the array is composed of the arguments that follow the index argument. The index argument determines which of the following values will be returned.

The following example returns the third item from the list of values that is provided.

SELECT CHOOSE ( 3, 'Manager', 'Director', 'Developer', 'Tester' ) AS Result;

Here is the result set.

Result
-------------
Developer

(1 row(s) affected)
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ