|
Should the syntax SUM(CASE ...) always be used or are there times when the CASE WHEN = 'x' then SUM() form be used when creating a conditional total? (This question arises from Phil Factor's answer in one of today's quesitons here).
(comments are locked)
|
|
It can lead to inconsistent coding like I always stick with
(comments are locked)
|
|
If you compate the two in an execution plan they are pretty much the same. I tried it with a table variable and throw-away code and saw that one did a sort then aggregate, the other an aggregate then a sort. The costs of them were the same, as they were doing a table scan. I can't imagine that it has a performance difference either way (YMMV - TEST TEST TEST!), but as ozamora states, it is easier to read and understand a
(comments are locked)
|
|
OK. You all have adventureworks. In order to get a report of the number of create and Alter Table statements, others, and the total, here's what I'd do, using this technique. It is probably not the most elegant but it allows you to tweak things to taste! --to maybe do this, for example... excellent +1 - now I don't need to find the throw-away code that i threw away :o)
Dec 02 '10 at 12:41 PM
WilliamD
dang this case-sensitive copy of AdventureWorks 8)
Dec 02 '10 at 06:23 PM
KenJ
(comments are locked)
|

