March 5, 2025 at 12:00 am
Comments posted to this topic are about the item Understanding the Logical Functions IIF and Choose in SQL Server 2022
March 5, 2025 at 11:55 pm
One thing about the CHOOSE function is that it seems to provide a tempting way to avoid having a normalised database with its lookup tables. I would be picky about when I use this, such as when we supply reports to an outside partner and their description of each level varies from ours.
----------------------------------------------------
March 6, 2025 at 1:24 pm
Thanks for the article. I'm struggling to find a situation where I would actually choose CHOOSE. (See what I did there?) I don't want to hard code values into CHOOSE. I would just have a look up table and join to it. What if I need to add a value? I would rather insert a record into a look up table than chase down every instance of CHOOSE to update. Am I missing something here?
Greg
March 6, 2025 at 5:56 pm
You don't have to hardcode the values. You can use values from tables as well, so this could get some dynamic-type sql choices. I have a table of beers and brewers. Look at this:
So I could pull values from different places and let the index choose which value is returned.
March 6, 2025 at 6:04 pm
Thanks, Steve. That makes more sense.
Viewing 5 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