SQL Choose() Function in SQL Server 2012
SQL Choose() function introduced with SQL Server 2012 returns an input argument from a list of input values at the desired index which is specified as an input arguement as well
The first input argument to the SQL Choose() function is "index" and it is in integer data type. The input arguments can be thought as an array with index starting from 1.
SQL CHOOSE() Function Samples
In this T-SQL tutorial, SQL programmers can find Choose() function sample codes which can help to understand where and how to use SQL Choose() function.
Choose() Function and Index Argument
The input index parameter or index argument to Choose() sql function can be a static integer value, or can be an integer variable parameter.
Choose() Function with Invalid Index
Of course it is possible to set the 1-based index value to zero (0) or to an index that is out of the range of the input array. In these cases the SQL Server Choose() function returns NULL as return value.
The index argument of the Choose() function can be NULL instead of a valid integer value. In such cases again, SQL Server function Choose() will return NULL value as output.
Choose() Function as an Expression to Concat() Function
Here is an other t-sql sample code where SQL Choose() function and Concat() function are used together in single SELECT statement. Note that the SQL Server Choose() function is used as an input expression argument to Concat() string concatenation function.
I hope T-SQL developers are ready to use SQL CHOOSE() function in their codes. If you wonder other T-SQL functions introduced with SQL Server 2012, you can find a list of functions here New T-SQL Functions in SQL Server 2012 and here SQL Analytic Functions in SQL Server 2012