If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
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, 10:34
andrewhallam andrewhallam is offline
Registered User
 
Join Date: Dec 2003
Location: Nottingham, England
Posts: 52
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, 15:42
ceinma ceinma is offline
Registered User
 
Join Date: Apr 2007
Location: Jundiai / SP - Brasil
Posts: 311
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
Jundiai / SP - Brasil
http://www.imartins.com.br/informix - em Português
http://www.imartins.com.br/informix - English (translated by Google).
________________________________________
Reply With Quote
  #3 (permalink)  
Old 01-10-08, 05:37
andrewhallam andrewhallam is offline
Registered User
 
Join Date: Dec 2003
Location: Nottingham, England
Posts: 52
RE: use the funciont NVL

Thanks for that - your a star.

Cheers.
Reply With Quote
  #4 (permalink)  
Old 01-10-08, 06:10
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
ceinma, what "undesirable result" does NVL(SUM(bomweight),0) produce?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 01-10-08, 06:47
ceinma ceinma is offline
Registered User
 
Join Date: Apr 2007
Location: Jundiai / SP - Brasil
Posts: 311
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
Jundiai / SP - Brasil
http://www.imartins.com.br/informix - em Português
http://www.imartins.com.br/informix - English (translated by Google).
________________________________________
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

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