Solved

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

Posted on 2014-12-17
8
75 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
 

Author Comment

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

Using version 11.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now