|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 4:24 AM
Points: 1,158,
Visits: 642
|
|
L' Eomot Inversé (1/12/2013)
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 BoL Returns the data type with the highest precedence from the set of types passed to the functionThe 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.
I read this and changed my mind to integer. Ah well, another point gone begging.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 2:02 PM
Points: 6,367,
Visits: 8,228
|
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 9:51 AM
Points: 1,891,
Visits: 936
|
|
Fun, easy, and educational. Excellent!
Not all gray hairs are Dinosaurs!
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 1:20 PM
Points: 2,573,
Visits: 1,531
|
|
| 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.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 1:54 AM
Points: 7,086,
Visits: 7,138
|
|
KWymore (1/14/2013) 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. 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).
Tom Que conclure à la fin de tous mes longs propos? C'est que les préjugés sont la raison des sots. (Voltaire, 1756)
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Yesterday @ 6:54 PM
Points: 721,
Visits: 1,375
|
|
L' Eomot Inversé (1/15/2013)
KWymore (1/14/2013) 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.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).
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.
Jason
Jason
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 10:44 AM
Points: 3,452,
Visits: 2,527
|
|
wolfkillj (1/15/2013)
L' Eomot Inversé (1/15/2013)
KWymore (1/14/2013) 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.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). 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. Jason Jason Sometimes is better to be late to the discussion: learned lot from Tom's comments.
So thanks to both Ron and Tom!
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 8:50 AM
Points: 746,
Visits: 435
|
|
Tom, thanks for your comments about Return type.
I don't have 2012 to understand it further.
-- Dineshbabu Desire to learn new things..
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 2:54 AM
Points: 152,
Visits: 154
|
|
wow... nice question.. really i learned new choose() functionality. i never ever used it.
Manik You cannot get to the top by sitting on your bottom.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, April 25, 2013 7:56 AM
Points: 843,
Visits: 209
|
|
| learned something about something I will never use :)
|
|
|
|