CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 MySQL Returning Null on Sum

Print topic Send  topic

Author Message
Edd
Posted: 10/14/2002, 7:05 AM

This is NOT a CCS issue it is just a information posting for CCS/CC users using MySQL.

It is just for some other poor slob's reference in case you don't RTFM. After wasting 2 days and increasing my four letter word vocabulary I thought I would document the issue.

If you are working with MySQL and you perform a SQL fetch where you only retrieve the Sum of a value and their are no values to sum then MySQL will return a Null Row - ADO will / can spit the dummy depending upon your release levels.

The MySQL manual (yeah! whoever reads TFM) quite rightly says 'If you sum values in MySQL and their are no values, then MySQL returns a Null - ANSI standard requirement.

Now you can all sleep in peace knowing this snippet of useless (unless you need it) crap.

Edd.
Brent
Posted: 10/14/2002, 9:50 AM

Try

select IFNULL(sum(colx),0) from table

This is in the manual at http://www.mysql.com/doc/en/Control_flow_functions.html
If the sum is NULL because all the column values are NULL or if there are no rows to sum,
then the value returned will be NULL and then converted 0.

Simple, eh? ;)
It took me all of 10 seconds to look it up on line even though I never used it before.
Why? Because I read the MySQL manual like other people read a novel, from cover to cover.
When you've got nothing to do, read 10 pages at a time. No one says you've got to read
the whole thing at a time. You learn a great deal of what is available and you'll
be able to use it when the need arises. Either that, or you can spend 2 days banging
your head against the wall everytime you have a problem. The choice is yours. If you choose
the latter, then I'd recommend you stock up on aspirin and poly filler.<g>

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.