What’s the SQL Server Equivalent of ELT() in MySQL?

In MySQL, you can use the ELT() function to return an item from a specified position in a list. SQL Server has a similar function, but with a different name.

In SQL Server, the CHOOSE() function does basically the same thing that the ELT() function does in MySQL. To be more precise, CHOOSE() is actually a Transact-SQL function, so it can also be used in Azure databases.

Example

The CHOOSE() function works like this:

SELECT CHOOSE(3, 'Cat', 'Dog', 'Horse') AS 'Result';

Result:

Result
------
Horse 

So it looks almost identical to the MySQL version (the only difference is the function name).

The MySQL Version

Here’s the same example, except using the MySQL syntax:

SELECT ELT(3, 'Cat', 'Dog', 'Horse') AS 'Result';

Result:

+--------+
| Result |
+--------+
| Horse  |
+--------+

The only difference is that you need to change ELT to CHOOSE in order to use it with SQL Server.

For more CHOOSE() examples see How to Find a List Item at a Specified Position in SQL Server.