|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 ================== |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 -- |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 ================== |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Jerry Stuckle wrote:
> SELECT c1 + IFNULL(c2, 0) + IFNULL(c3,0) ... ok, it works, thanks bye, max |
|
![]() |
| Outils de la discussion | |
|
|