Working with Choose in-built Sql-Server Function.

Posted by in Sql Server category on for Beginner level | Points: 250 | Views : 3294 red flag

In this article,we will learn about working with CHOOSE in-built SQL Server Function.


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.


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:-


In this article we have learned about Choose Function and it's implementation.

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: vishal kumar
Member Level: Platinum
Member Status: Member,MVP
Member Since: 11/5/2013 5:58:17 AM
Country: India

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)