|
(SQL Server 2008 R2.)
(CASE WHEN cTT.Total IS NOT NULL THEN cTT.Total ELSE 0 END) as 'Total_Total'
A dozen of these in a view...
|
|
|
|
|
What exactly are they selling? Give me the URL. Please. I would like to buy that Mars rover for null.
"Bastards encourage idiots to use Oracle Forms, Web Forms, Access and a number of other dinky web publishing tolls.", Mycroft Holmes[ ^]
|
|
|
|
|
I'm sure you can just go pick one up; there's no security around.
|
|
|
|
|
PIEBALDconsult wrote: Total_Total
What's the second "total" for? Did the programmer have total recall?
|
|
|
|
|
Normal people might call it a "Grand total".
|
|
|
|
|
Nope. It's a symbol for Total/scoreTotal. He's calculating GPA or something.
"Bastards encourage idiots to use Oracle Forms, Web Forms, Access and a number of other dinky web publishing tolls.", Mycroft Holmes[ ^]
|
|
|
|
|
There are plenty of dumb things done in SQL. Could be the coder never heard of ISNULL. Could be he came from a programming background. Could be he doesn't realize ISNULL is more efficient than a case statement. Could be a misapplication of "don't execute a function in a where clause" rule. Could be he forgot about ISNULL. Could be he's in the "Let's obsfucate this code as much as possible" club.
At least it isn't SUM(CASE WHEN cTT.Total IS NOT NULL THEN cTT.Total ELSE 0 END) as 'Total_Total'
|
|
|
|
|
KP Lee wrote: At least it isn't ...
I think that's in a few other places.
This is an improvement over some earlier code by the same guy that is something like:
SELECT
(SELECT COUNT(*) FROM T WHERE ... ) A ,
(SELECT COUNT(*) FROM T WHERE ... ) B ,
(SELECT COUNT(*) FROM T WHERE ... ) C ,
...
|
|
|
|
|
Maybe he wants the code to be ANSI compatible.
In which case I would use COALESCE.
People say nothing is impossible, but I do nothing every day.
|
|
|
|