Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding 2 fields in SQL statement where 1 field is NULL

Status
Not open for further replies.

uhu

IS-IT--Management
May 21, 2003
40
NZ
Hi everyone,

I'm trying to execute this statement

SELECT integervalue1 + integervalue2
INTO totalvalue
FROM testingtable

When both integervalue 1 & 2 are not NULL then everything is fine. but when integervalue1 = NULL then I'll get totalvalue = NULL.

Is there any tricks to overcome this limitation directly in SQL statement?? (other than getting the values individually and test if it's null or not)

THanks in advance,

vito
 
Hi,

Yes, the trick is use the built-in SQL NVL function.

SELECT NVL(integervalue1,0) + NVL(integervalue2,0)
INTO totalvalue
FROM testingtable

Regards,
Shriyan
 
Thank u very much Shriyan..
wow.. you're the real INFORMIX GURU here :)

vito
 
vito,

You are welcome. Thanks for the compliments. Your expression of praise and admiration, makes me to serve the forum members with more responsibility, vigour & strenuosity.

Regards,
Shriyan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top