* IvanLatysh
>  >> I've got query like this:
>
>  >> "select count(ID) from TABLE where (TABLE.A + TABLE.B + TABLE.C +
>  >> TABLE.D) > 0"
>
>  >> A,B,C,D are decimal values.
>
>  >> The problem is, I think, with NULL columns. Often B,C and D don't
>  >> have decimal value, but NULL.
>  >> I thought, that this should be counted like zero. Am I wrong ?
>
>  RB> NULL is not the same as zero.
>
>  RB> If any of the field values are NULL, the result of the expression is
>  RB> NULL.
>
> Hey guys Is this so hard to help people instead of killing them ?

I'm sorry, it was not my intention to "kill" anyone!

> Use IFNULL(null_field, 0)
>
> And your query will be like:
> select count(ID) from TABLE where (IFNULL(TABLE.A, 0) +
> IFNULL(TABLE.B, 0) + IFNULL(TABLE.C, 0)
> +  IFNULL(TABLE.D,0)) > 0

In general, I agree that it is better to provide an example of how to do it,
as you do here, but in this case I thought it may be a better solution to
avoid having NULL's in the table in the first place. But I don't know if
there are other reasons he have the NULL's... instead of trying to guess
what he wanted, I just gave him the facts on something he was obviously
confused about...

--
Roger
query


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to