Avatar of Sheldon Livingston
Sheldon LivingstonFlag for United States of America

asked on 

Pervasive SQL addition of fields where one or more may be null

Hello...

I'd like to write a query that gives me ((Field A + Field B) - (Field C + Field D))

I get a blank, perhaps NULL, if any of the fields are null.  Thus Field A may be 22 but if fields C, D or E are null then the answer appears to be null.

Any Advice.
SQL

Avatar of undefined
Last Comment
Sheldon Livingston
Avatar of Bill Bach
Bill Bach
Flag of United States of America image

You don't mention the exact version of PSQL, but the later versions support the IFNULL() function.  Basically, if the field is non-null, the field is returned.  If it is null, the alternate value is returned.  In arithmetic like this, it would simply be:
    ((IFNULL(FieldA,0) + IFNULL(FieldB,0)) - (IFNULL(FieldC,0) + IFNULL(FieldD,0)))
Avatar of Sheldon Livingston

ASKER

Sorry... should have clarified.  I'm want to sum up... thus:

SUM ((IFNULL(FieldA,0) + IFNULL(FieldB,0)) - (IFNULL(FieldC,0) + IFNULL(FieldD,0))) = Something

IFNULL isn't a valid scalar function...
Avatar of Bill Bach
Bill Bach
Flag of United States of America image

IFNULL() is certainly valid in the current release:
    http://docs.pervasive.com/products/database/psqlv11/wwhelp/wwhimpl/js/html/wwhelp.htm#href=ODBC/scalarfunc.05.6.html#1138644

Perhaps you can try ISNULL() instead.  Better yet, include the exact version number that you ARE using....
Avatar of Sheldon Livingston

ASKER

I get a "Invalid scalar funtion: ISNULL" or IFNULL.

Using version 11.
Avatar of Bill Bach
Bill Bach
Flag of United States of America image

Very odd.  I just ran this test query on PSQLv11.30 using the DEMODATA database:
   SELECT ISNULL(Last_Name,'') FROM Person
and it works fine.  Can you test the same query?  I also ran it with IFNULL(), too.
Avatar of Sheldon Livingston

ASKER

No idea what the issue is... everything is return the same error.
ASKER CERTIFIED SOLUTION
Avatar of Bill Bach
Bill Bach
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Sheldon Livingston

ASKER

I reinstalled Pervasive and now all is well...
SQL
SQL

SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.

61K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo