In this article we will understand this new logical function named CHOOSE in SQL Server 2012.
So here is how the syntax of CHOOSE looks like
CHOOSE ( index, val_1, val_2 [, val_n ] )
Now let us use this in the below code and understand the output.
declare @MyFavouriteClub as int = 5 SELECT choose(@MyFavouriteClub, 'Arsenal', 'Chelsea', 'Liverpool', 'Everton', 'Manchester United', 'Sunderland', 'Fulham')
Now lets see the output of the above
So what the function does is pulls out the 5th value from the data set and dispalys as a result set. CHOOSE works like an index into an array, where the array contains values or arguments. The index value\argument determines which of the containing values will be returned. If no match is found then a NULL is returned.
Tagged: Analytical functions in SQL Server 2012, CHOOSE function, New Analytical functions in SQL Server 2012, New features in SQL Server 2012, SQL Server 2012
Leave a Reply