﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by bitbucket  / T-SQL 2012 #2 / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 15:37:48 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>learned something about something I will never use :)</description><pubDate>Fri, 22 Feb 2013 01:03:34 GMT</pubDate><dc:creator>jfgoude</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>wow... nice question.. really i learned new choose() functionality. i never ever used it.:w00t:</description><pubDate>Tue, 22 Jan 2013 02:29:04 GMT</pubDate><dc:creator>manik123</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Tom, thanks for your comments about Return type.I don't have 2012 to understand it further.</description><pubDate>Thu, 17 Jan 2013 00:06:38 GMT</pubDate><dc:creator>Dineshbabu</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>[quote][b]wolfkillj (1/15/2013)[/b][hr][quote][b]L' Eomot Inversé (1/15/2013)[/b][hr][quote][b]KWymore (1/14/2013)[/b][hr]Thanks for the 2012 question. I'm not sure why I would ever use CHOOSE. I would usually join to a reference table, or use a case statement, or create a temp table if it was a small set of values to type up for an ad-hoc query or one off report. This does seem more geared towards .NET developers. I think if I came across it in production I would have to turn the array into a reference table.[/quote]If you would sometimesd use a CASE expression for this, why object to CHOOSE?  It's just a simplified syntax for CASE in a particular case.  Presumably it does index into the list, so it will have better performance than case when it is applicable (because the optimiser surely isn't going to look and see if the set of values for a simple case statement provides an ungapped sequence).[/quote]Hi Tom, Check my post above (about a page back in this thread) - the optimizer produces an execution plan with a Compute Scalar operator for CHOOSE with a defined value that is identical to that of CASE. It looks like the T-SQL implementation of CHOOSE truly is nothing but an alternative syntax for CASE when writing a conditional expression based on an equality comparison of integer values. SQL Server treats them exactly the same way. JasonJason[/quote]Sometimes is better to be late to the discussion: learned  lot from Tom's comments.So thanks to both Ron and Tom!</description><pubDate>Wed, 16 Jan 2013 13:28:38 GMT</pubDate><dc:creator>Revenant</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>[quote][b]L' Eomot Inversé (1/15/2013)[/b][hr][quote][b]KWymore (1/14/2013)[/b][hr]Thanks for the 2012 question. I'm not sure why I would ever use CHOOSE. I would usually join to a reference table, or use a case statement, or create a temp table if it was a small set of values to type up for an ad-hoc query or one off report. This does seem more geared towards .NET developers. I think if I came across it in production I would have to turn the array into a reference table.[/quote]If you would sometimesd use a CASE expression for this, why object to CHOOSE?  It's just a simplified syntax for CASE in a particular case.  Presumably it does index into the list, so it will have better performance than case when it is applicable (because the optimiser surely isn't going to look and see if the set of values for a simple case statement provides an ungapped sequence).[/quote]Hi Tom, Check my post above (about a page back in this thread) - the optimizer produces an execution plan with a Compute Scalar operator for CHOOSE with a defined value that is identical to that of CASE. It looks like the T-SQL implementation of CHOOSE truly is nothing but an alternative syntax for CASE when writing a conditional expression based on an equality comparison of integer values. SQL Server treats them exactly the same way. JasonJason</description><pubDate>Tue, 15 Jan 2013 13:12:50 GMT</pubDate><dc:creator>wolfkillj</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>[quote][b]KWymore (1/14/2013)[/b][hr]Thanks for the 2012 question. I'm not sure why I would ever use CHOOSE. I would usually join to a reference table, or use a case statement, or create a temp table if it was a small set of values to type up for an ad-hoc query or one off report. This does seem more geared towards .NET developers. I think if I came across it in production I would have to turn the array into a reference table.[/quote]If you would sometimesd use a CASE expression for this, why object to CHOOSE?  It's just a simplified syntax for CASE in a particular case.  Presumably it does index into the list, so it will have better performance than case when it is applicable (because the optimiser surely isn't going to look and see if the set of values for a simple case statement provides an ungapped sequence).</description><pubDate>Tue, 15 Jan 2013 13:00:41 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Thanks for the 2012 question. I'm not sure why I would ever use CHOOSE. I would usually join to a reference table, or use a case statement, or create a temp table if it was a small set of values to type up for an ad-hoc query or one off report. This does seem more geared towards .NET developers. I think if I came across it in production I would have to turn the array into a reference table.</description><pubDate>Mon, 14 Jan 2013 17:16:33 GMT</pubDate><dc:creator>KWymore</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Fun, easy, and educational.  Excellent!</description><pubDate>Mon, 14 Jan 2013 12:53:25 GMT</pubDate><dc:creator>Miles Neale</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>[quote][b]Koen Verbeeck (1/14/2013)[/b][hr]Great question about a new 2012 feature. Thanks Ron!(and thanks for including me ;-))[/quote]+1</description><pubDate>Mon, 14 Jan 2013 11:59:39 GMT</pubDate><dc:creator>WayneS</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>[quote][b]L' Eomot Inversé (1/12/2013)[/b][hr]Nice clear straightforward question.Good to see a question on this new feature.  Interestingly, there's an error on the BoL page: it says the CHOOSE function [quote][b]BoL[/b][hr]Returns the data type with the highest precedence from the set of types passed to the function[/quote]The first argument is an integer, which has a higher type precedence than any character type, but if it really was going to return an int we would have string to int conversion errors here.  BoL should instead say that the return type is highest precedence type of the arguments other than the first.[/quote]I read this and changed my mind to integer.Ah well, another point gone begging.</description><pubDate>Mon, 14 Jan 2013 09:28:08 GMT</pubDate><dc:creator>paul s-306273</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>[quote][b]L' Eomot Inversé (1/12/2013)[/b][hr]Nice clear straightforward question.Good to see a question on this new feature.  Interestingly, there's an error on the BoL page: it says the CHOOSE function [quote][b]BoL[/b][hr]Returns the data type with the highest precedence from the set of types passed to the function[/quote]The first argument is an integer, which has a higher type precedence than any character type, but if it really was going to return an int we would have string to int conversion errors here.  BoL should instead say that the return type is highest precedence type of the arguments other than the first.[/quote]I read this and changed my mind to integer.Ah well, another point gone begging.</description><pubDate>Mon, 14 Jan 2013 09:26:47 GMT</pubDate><dc:creator>paul s-306273</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>[quote][b]SQLRNNR (1/12/2013)[/b][hr]Glad we have this feature added.[/quote]But are the CHOOSE function and its also-new-to-SQL-Server-2012 buddy IIF anything other than syntactical sugar for Visual Basic coders writing T-SQL? The CHOOSE function is just a less-flexible shorthand for the ANSI-standard CASE, and it can only be used when evaluating an equality condition for an integer value (the index argument), although I concede that CHOOSE requires less typing than CASE in these limited circumstances. Similarly, the IIF function saves a few keystrokes when there are only two possible values to return, but once you start nesting IIF statements, the code becomes more difficult to understand than the equivalent CASE expression, in my opinion. SQL Server 2012 just converts CHOOSE and IIF function calls to CASE expressions anyway. I have a code sample that shows that the CHOOSE and IIF functions produce Compute Scalar operators that have Defined Values that are identical to the one produced by the equivalent CASE expression, but I'm having some trouble posting it. I'll try again later.[b]Edit: [/b] I have posted a screenshot of the code, a .txt file of the code, and a .sqlplan file of the execution plan that I get on my SQL Server 2012 instance, if you're interested. Still not sure why I can't post code - I get an error screen that suggests that my employer is blocking the outgoing traffic when it includes certain kinds of code snippets - hmmm . . .</description><pubDate>Mon, 14 Jan 2013 09:09:58 GMT</pubDate><dc:creator>wolfkillj</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>[quote][b]Toreador (1/14/2013)[/b][hr]What would be a good use of this function?Why wouldn't you just add a lookup table containing the index and description, and join to that?So that any changes required to a description could be made by just updating the lookup table, rather than rewriting SQL.[/quote]This was exactly what I was wondering.</description><pubDate>Mon, 14 Jan 2013 08:36:22 GMT</pubDate><dc:creator>(Bob Brown)  </dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Thanks, for the reminder about the Choose function. The beauty  is the ability to provide two things, an alternate name or identification as well as a different sort order than if the value provided was the content of the field. Of course this really only works well if there is a short list of values to translate.</description><pubDate>Mon, 14 Jan 2013 08:33:45 GMT</pubDate><dc:creator>Lon-860191</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>[quote][b]Koen Verbeeck (1/14/2013)[/b][hr]Great question about a new 2012 feature. Thanks Ron![/quote]I must concur... that's a neat function that I had missed.  I got this one right because there was only one answer that made sense, returning an integer after being given a bunch of comma separated strings wouldn't make sense to me, but I didn't know about choose until now.  :)</description><pubDate>Mon, 14 Jan 2013 08:11:16 GMT</pubDate><dc:creator>mtassin</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Thanks for the question.</description><pubDate>Mon, 14 Jan 2013 07:46:22 GMT</pubDate><dc:creator>(Bob Brown)  </dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>What would be a good use of this function?Why wouldn't you just add a lookup table containing the index and description, and join to that?So that any changes required to a description could be made by just updating the lookup table, rather than rewriting SQL.</description><pubDate>Mon, 14 Jan 2013 07:30:57 GMT</pubDate><dc:creator>Toreador</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Great question about a new feature.</description><pubDate>Mon, 14 Jan 2013 07:23:38 GMT</pubDate><dc:creator>Dana Medley</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Good introduction the CHOOSE function.</description><pubDate>Mon, 14 Jan 2013 06:32:45 GMT</pubDate><dc:creator>Mike Hays</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Thanks for a Monday question, that still made me learn something.</description><pubDate>Mon, 14 Jan 2013 05:03:12 GMT</pubDate><dc:creator>Thomas Abraham</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Great question about a new 2012 feature. Thanks Ron!(and thanks for including me ;-))</description><pubDate>Mon, 14 Jan 2013 01:28:56 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Thanks a lot for this question. Got to know about CHOOSE function. Very helpful. :-)</description><pubDate>Mon, 14 Jan 2013 00:06:50 GMT</pubDate><dc:creator>sqlnaive</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Interesting question, thanks Ron</description><pubDate>Mon, 14 Jan 2013 00:05:52 GMT</pubDate><dc:creator>Stewart "Arturius" Campbell</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>[quote][b]Lokesh Vij (1/13/2013)[/b][hr]Wow.. Thanks Ron for another one on SS2012 :-)[/quote]+1Thanks for the question..</description><pubDate>Sun, 13 Jan 2013 22:27:17 GMT</pubDate><dc:creator>demonfox</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Wow.. Thanks Ron for another one on SS2012 :-)</description><pubDate>Sun, 13 Jan 2013 22:16:08 GMT</pubDate><dc:creator>Lokesh Vij</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>[quote][b]bitbucket-25253 (1/12/2013)[/b][hr][quote][b]L' Eomot Inversé (1/12/2013)[/b][hr]Nice clear straightforward question.Good to see a question on this new feature.  Interestingly, there's an error on the BoL page: it says the CHOOSE function [quote][b]BoL[/b][hr]Returns the data type with the highest precedence from the set of types passed to the function[/quote]The first argument is an integer, which has a higher type precedence than any character type, but if it really was going to return an int we would have string to int conversion errors here.  BoL should instead say that the return type is highest precedence type of the arguments other than the first.[/quote]From the supporting link in the question [quote]CHOOSE acts like an index into an array, where the array is composed of the arguments that follow the index argument. The index argument determines which of the following values will be returned.[/quote][/quote]Yes, it says that.  But that says nothing about the type returned, it's about which value is selected before any necessary type conversion is done.  The same page contains the incorrect statement that I quoted, which says nothing about which value is selected, only about which type it is to be converted to (which it gets wrong).</description><pubDate>Sat, 12 Jan 2013 18:25:35 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Glad we have this feature added.</description><pubDate>Sat, 12 Jan 2013 17:18:06 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>[quote][b]L' Eomot Inversé (1/12/2013)[/b][hr]Nice clear straightforward question.Good to see a question on this new feature.  Interestingly, there's an error on the BoL page: it says the CHOOSE function [quote][b]BoL[/b][hr]Returns the data type with the highest precedence from the set of types passed to the function[/quote]The first argument is an integer, which has a higher type precedence than any character type, but if it really was going to return an int we would have string to int conversion errors here.  BoL should instead say that the return type is highest precedence type of the arguments other than the first.[/quote]From the supporting link in the question [quote]CHOOSE acts like an index into an array, where the array is composed of the arguments that follow the index argument. The index argument determines which of the following values will be returned.[/quote]</description><pubDate>Sat, 12 Jan 2013 13:45:18 GMT</pubDate><dc:creator>bitbucket-25253</dc:creator></item><item><title>RE: T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Nice clear straightforward question.Good to see a question on this new feature.  Interestingly, there's an error on the BoL page: it says the CHOOSE function [quote][b]BoL[/b][hr]Returns the data type with the highest precedence from the set of types passed to the function[/quote]The first argument is an integer, which has a higher type precedence than any character type, but if it really was going to return an int we would have string to int conversion errors here.  BoL should instead say that the return type is highest precedence type of the arguments other than the first.</description><pubDate>Sat, 12 Jan 2013 12:41:29 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>T-SQL 2012 #2</title><link>http://www.sqlservercentral.com/Forums/Topic1406405-1222-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/95646/"&gt;T-SQL 2012 #2&lt;/A&gt;[/B]</description><pubDate>Sat, 12 Jan 2013 12:32:06 GMT</pubDate><dc:creator>bitbucket-25253</dc:creator></item></channel></rss>