Solved

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

Posted on 2014-12-17
8
92 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

710 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