In this article,we will learn about working with CHOOSE in-built SQL Server Function.
Introduction
As the name suggests,CHOOSE would pick specified value based on index number or position number.It's introduced in SQL Server 2012.
CHOOSE is one of the new built-in logical function introduced as a Part of SQL Server 2012. It returns the value at the specified index position from the list of values.
If Index is numeric,then it is converted to integer.On the other hand,if index is greater than the element in the list,then it returns NULL.
CHOOSE acts like an index into an array,where the array is composed of the arguments that follow the index argument.
Objective
Working with Choose in-built Sql-Server Function.
Using the code
Example1:-CHOOSE Basic Example
Output would be:-
Example2:- CHOOSE function with variables as index and values.
Output would be:-
Example 3: CHOOSE will return NULL if INDEX position is outside the range of values.
Output would be:-
Example 4: If index value is numeric,it will be implicitly converted to INT.
Output would be:-
Example 5: CHOOSE function Return Data-type will be the one with highest precedence from
the Data-types of the list of values.
Output would be:-
Conclusion
In this article we have learned about Choose Function and it's implementation.