Did you know the CHOOSE function in SQL Server? This function introduced with SQL Server 2012.
1 |
SELECT ..., 'xxx' = CASE WHEN yyy = 1 THEN 'xy' ... END ... |
The CHOOSE command can provide practical use for situations such as the example above.
For example:
1 |
SELECT CHOOSE (field1, 'Manager', 'Director', 'Developer', 'Tester' ) AS Result FROM myTable1; |
Here is the CASE WHEN version of the command I wrote above with CHOOSE:
1 2 3 4 5 |
SELECT 'Result' = CASE WHEN field1= 1 THEN 'Manager' WHEN field1= 2 THEN 'Director' WHEN field1= 3 THEN 'Developer' WHEN field1= 4 THEN 'Tester' END FROM myTable1 |
It doesn’t contribute to performance, but as I said, it makes it easy to write code.