PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > null value
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
null value

Réponse
 
LinkBack Outils de la discussion
Vieux 03/04/2008, 10h15   #1
Massimo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut null value

Hi,
i have a problem with the following query:

select (c1+c2+c3) as tot from tab

c2 or c3 can have value null.
When c1 or c2 are null, tot=null but i need that tot=c1

Thanks

bye,
max


  Réponse avec citation
Vieux 03/04/2008, 13h28   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: null value

Massimo wrote:
> Hi,
> i have a problem with the following query:
>
> select (c1+c2+c3) as tot from tab
>
> c2 or c3 can have value null.
> When c1 or c2 are null, tot=null but i need that tot=c1
>
> Thanks
>
> bye,
> max
>
>
>


SELECT c1 + IFNULL(c2, 0) + IFNULL(c3,0) ...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 04/04/2008, 05h11   #3
ThanksButNo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: null value

On Apr 3, 5:28 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Massimo wrote:
> > Hi,
> > i have a problem with the following query:

>
> > select (c1+c2+c3) as tot from tab

>
> > c2 or c3 can have value null.
> > When c1 or c2 are null, tot=null but i need that tot=c1

>

....
>
> SELECT c1 + IFNULL(c2, 0) + IFNULL(c3,0) ...
>
> --



You probably should include "IFNULL(c1, 0) ... ", just in case.

I always like to prepare for things like that, columns becoming null
unexpectedly -- especially when the customer assures me that's it's
*impossible* for that value to come in null --
  Réponse avec citation
Vieux 04/04/2008, 13h24   #4
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: null value

ThanksButNo wrote:
> On Apr 3, 5:28 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> Massimo wrote:
>>> Hi,
>>> i have a problem with the following query:
>>> select (c1+c2+c3) as tot from tab
>>> c2 or c3 can have value null.
>>> When c1 or c2 are null, tot=null but i need that tot=c1

> ...
>> SELECT c1 + IFNULL(c2, 0) + IFNULL(c3,0) ...
>>
>> --

>
>
> You probably should include "IFNULL(c1, 0) ... ", just in case.
>
> I always like to prepare for things like that, columns becoming null
> unexpectedly -- especially when the customer assures me that's it's
> *impossible* for that value to come in null --
>


I would have, but he specifically indicated c2 and c3 could be null, but
not c1.

If c1 is declared as NOT NULL, it's not required. But I agree with you,
if it could be null, I would also set it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 04/04/2008, 14h34   #5
Massimo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: null value

Jerry Stuckle wrote:

> SELECT c1 + IFNULL(c2, 0) + IFNULL(c3,0) ...


ok, it works, thanks

bye,
max



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h17.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12986 seconds with 13 queries