January 20, 2020 at 12:00 am
Comments posted to this topic are about the item Choosing the Column
January 20, 2020 at 5:23 am
Nice, easy one to start the week on, thanks Steve
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
January 20, 2020 at 1:58 pm
I have never found a use for the CHOOSE function. Has anybody used this in production for anything? If so I would be curious to hear about the situation in which it was useful. It seems like an interesting function but not really useful in practice.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 20, 2020 at 3:14 pm
I've used CHOOSE to translate an error number into a descriptive reason in SSRS.
DECLARE @ErrorNum int = 2;
SELECT CHOOSE(@ErrorNum, 'Failed due to reason X', 'Failed due to reason Y', 'Failed due to reason Z');
January 20, 2020 at 3:20 pm
I've used CHOOSE to translate an error number into a descriptive reason in SSRS.
DECLARE @ErrorNum int = 2;
SELECT CHOOSE(@ErrorNum, 'Failed due to reason X', 'Failed due to reason Y', 'Failed due to reason Z');
That is pretty much the type of example I have always seen. I would prefer a lookup table for this kind of thing nearly always so I can just adjust the lookup table and everything else just continues to work. But I guess I can see it being useful in a pretty limited fashion.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 22, 2020 at 2:31 pm
I agree, CHOOSE and IIF both seem to be either special cases of CASE or linking to a reference table. Having a reference table is far easier to maintain than finding every time you add an error type (or whatever else), so unless they run more efficiently that CASE for a particular circumstance, it doesn't seem worthwhile.
I suspect the reason they added these is to make Access knowledge more portable to SQL Server.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy