Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-12-17
8
Medium Priority
?
133 Views
Last Modified: 2015-01-08
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.
0
Comment
Question by:classnet
  • 4
  • 4
8 Comments
 
LVL 28

Expert Comment

by:Bill Bach
ID: 40505230
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)))
0
 

Author Comment

by:classnet
ID: 40505236
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...
0
 
LVL 28

Expert Comment

by:Bill Bach
ID: 40505263
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....
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:classnet
ID: 40505270
I get a "Invalid scalar funtion: ISNULL" or IFNULL.

Using version 11.
0
 
LVL 28

Expert Comment

by:Bill Bach
ID: 40505318
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.
0
 

Author Comment

by:classnet
ID: 40505379
No idea what the issue is... everything is return the same error.
0
 
LVL 28

Accepted Solution

by:
Bill Bach earned 2000 total points
ID: 40505405
I checked the PSQLv10 documentation from 2007, and both IFNULL and ISNULL are supported there.  So, ALL versions of v11 should work, too.   Are you accessing data on your LOCAL machine, or on a REMOTE server?  If a remote server, right-click the Server Name in the PCC and select Properties.  When prompted at the login box, click cancel, an dyou should see the version of the database engine on the server.

If you are using a local engine, do you have a full PSQL installation, or do you have a custom installation from an application vendor, such as Sage (Timberline).  This vendor provides a custom ODBC driver and may not support the IFNULL function.
0
 

Author Closing Comment

by:classnet
ID: 40538237
I reinstalled Pervasive and now all is well...
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question