Understanding the Logical Functions IIF and Choose in SQL Server 2022

  • Comments posted to this topic are about the item Understanding the Logical Functions IIF and Choose in SQL Server 2022

  • 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.

    ----------------------------------------------------

  • 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

     

  • 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:

    2025-03_0144

    So I could pull values from different places and let the index choose which value is returned.

  • Thanks, Steve.  That makes more sense.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply