One other thought. SUM will return NULL if the query without the SUM would return no rows or if all the rows returned contain NULL values for the column in question. Are you sure you're running the same query against the same database table in the command prompt vs Perl? Are you using the same username etc? | [reply] |
... Next morning ...
A thousand pardons dear Monks.
In my application I have batches of data that can be added from time to time. When I run my code I don't know for sure if a batch currently exists. Because of this my SQL statement (including a lot of WHERE stuff) will be expected to return a NULL from time to time. Thus I used a simple "foolproof" way of testing for a null return. ... Yes, you guessed it, my "foolproof" code was actually "foolish" code. Let's just label it an "Intro to Computing 101, week #1 error" and let it fade away.
BUT, that leaves me with my current "foolproof code".
my $found_something = 0;
while (@val = $sth -> fetchrow_array())
{
      # useful database code goes here
      $found_something = 1;
}
if ($found_something == 0)
{
      # "graceful" found nothing code goes here
}
This should work, but it has a bit of a "bailing wire and chewing gum" look to it. Is there a cleaner way to do it?
Thanks for the help and sorry for error on my part.
Bruce
| [reply] |