I'd be surprised if this hasn't been asked before, but I haven't been able to find anything. Excel has a function
CHOOSE(n, x_1, x_2, x_3, ...)
which returns x_n for the given value of n.
Is there anything similar in SQL (either standard or MS-specific) supported by SQL Server 2008? I know it should really be implemented using a lookup table in the database, but for what I'm doing I'm not able to add new tables to the database.
I could create a temporary table and populate it from the SQL script, or use
CASE n WHEN 1 THEN x_1 WHEN 2 THEN x_2 WHEN 3 THEN x_3 ... END
but is there anything less cumbersome?
Unfortuantely, no it seems not to be the present in your version.
The CHOOSE
-Function is only available since SQL Server 2012 and works quite the same as you describe the Excel-function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With