Solved

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

Posted on 2014-12-17
8
99 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

 

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 500 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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 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