in reply to Re: (2) Need help with DBI
in thread DBI compare columns problem

It sounds like one of the columns in your table has NULL values. Try to add nvl to your SELECT statement, and also try to change
($mb_award,$mb_accept) = $dbh->fetchrow_array();
to two steps -
use Data::Dumper; ... my @res = $dbh->fetchrow_array(); print Dumper(@res); $mb_award = $res[0]; $mb_accept = $res[1];
Use the Data::Dumper module to investigate your variables - I suspect you will see an undef in @res (because one of the column might be NULL).

One last observation is that your test of greater than "0.00" does not work if both values are equal to "0.00" or one is "0.00" and the other is NULL. In other words, the test is incomplete. Perhaps you need to add some exception handling...

if ($mb_award > 0) { $mb_amount_disp = $mb_award; } elsif ($mb_accept > 0) { $mb_amount_disp = $mb_accept; } else { # both values are <= 0 or undef, what shall I do? .... }

Replies are listed 'Best First'.
Re: Re: (3) DBI compare columns problem
by shenme (Priest) on Sep 17, 2003 at 18:08 UTC
    Good advice about Data::Dumper and actually getting to 'see' the results.   But he's using MySQL which doesn't have nvl() so he can't use that.   I can find references to nvl() in Oracle and FoxPro docs, but not MySQL.   As I look, the closest equivalent in MySQL would be   ifnull(expr1,expr2).