Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Informix > Error: IS [NOT] NULL predicate may be used only with simple columns. (State:S1000, Na

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-09-08, 11:34
andrewhallam andrewhallam is offline
Registered User
 
Join Date: Dec 2003
Posts: 28
Angry Error: IS [NOT] NULL predicate may be used only with simple columns. (State:S1000, Na

Anyone know of a way to use CASE with SUM and NOT NULL in an INFORMIX SQL SELECT statement?

The below SQL works fine in SQL SERVER and DB2 but INFORMIX doesn't like it. (For info - there are no rows matching on bom for bomparent = 'XXX')


SELECT CASE WHEN SUM(bomweight) IS NULL THEN 0 ELSE SUM(bomweight) END AS weight
FROM bom WHERE bomparent = 'XXX'

Error: IS [NOT] NULL predicate may be used only with simple columns. (State1000, Native Code: FFFFFEDB)

Now I could use the ANSI standard COALESCE() function (similar to SQL SERVER ISNULL()) to obtain the same result but again unfortunately INFORMIX does not support this either.

SELECT COALESCE(SUM(bomweight), 0) AS weight
FROM bom WHERE bomparent = 'XXX'

-Under SQLSERVER and DB2 the result is one row:
WEIGHT
0.0

Thanks in advance for your help on this.

Andy
ahmatexeldotcodotuk
Reply With Quote
  #2 (permalink)  
Old 01-09-08, 16:42
ceinma ceinma is offline
Registered User
 
Join Date: Apr 2007
Location: Distrito Federal - Brasil
Posts: 197
use the funciont NVL
Code:
SELECT NVL(SUM(bomweight) ,0) AS weight FROM bom WHERE bomparent = 'XXX'
But this can retreive undesirable result ..

the corret way to use is:
Code:
SELECT SUM(NVL(bomweight,0)) AS weight FROM bom WHERE bomparent = 'XXX'
__________________
________________________________________
César Inacio Martins
Distrito Federal - Brasil
________________________________________
Reply With Quote
  #3 (permalink)  
Old 01-10-08, 06:37
andrewhallam andrewhallam is offline
Registered User
 
Join Date: Dec 2003
Posts: 28
RE: use the funciont NVL

Thanks for that - your a star.

Cheers.
Reply With Quote
  #4 (permalink)  
Old 01-10-08, 07:10
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
ceinma, what "undesirable result" does NVL(SUM(bomweight),0) produce?
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #5 (permalink)  
Old 01-10-08, 07:47
ceinma ceinma is offline
Registered User
 
Join Date: Apr 2007
Location: Distrito Federal - Brasil
Posts: 197
on reality, with sum and any other aggregate function the NULLs values are ignored...so, works too. But just to a good practice must avoid this kind of code... my opinion..
__________________
________________________________________
César Inacio Martins
Distrito Federal - Brasil
________________________________________
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On