Home > Ask the AS/400 Experts > DB2/400 and DB2 UDB Questions & Answers > SQL statement error
Ask The iSeries 400 Expert: Questions & Answers
EMAIL THIS

SQL statement error

Kent Milligan EXPERT RESPONSE FROM: Kent Milligan

Pose a Question
Other iSeries 400 Categories
Meet all iSeries 400 Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 13 September 2006
I am running the following SQL statement but getting an error as "Position 1 Null values not allowed in column or variable VC_EST_PAYMENT

  
UPDATE UARSLSDET AS A SET (VC_EST_PAYMENT, FEE) =                 
   (SELECT IFNULL(EST_PAYMENT*100,0), IFNULL(FEE*100,0)           
       FROM UARVCDFT AS B                                         
       WHERE B.PLANTYPE = A.PLANTYPE  AND B.PRODUCT = A.PRODSOLD) 
    WHERE A.THIRD_PARTY <> '0'  AND VC_EST_PAYMENT = -1" 

Do you know what I am doing wrong?


>
EXPERT RESPONSE
This is a fairly common mistake when coding an UPDATE statement with a subselect. What is likely happening is that there is no matching row in table B (UARVCDFT) for the condition B.PLANTYPE = A.PLANTYPE AND B.PRODUCT = A.PRODSOLD. In this case the IFNULL function never even gets executed for that row, because the subselect didn't return a row and DB2 has to set the column to the null value. You need to make sure that a matching row exists for the inner table.

Try this: 

UPDATE UARSLSDET AS A SET (VC_EST_PAYMENT, FEE) =                 
   (SELECT IFNULL(EST_PAYMENT*100,0), IFNULL(FEE*100,0)           
       FROM UARVCDFT AS B                                         
       WHERE B.PLANTYPE = A.PLANTYPE  AND B.PRODUCT = A.PRODSOLD) 
    WHERE A.THIRD_PARTY <> '0'  AND VC_EST_PAYMENT = -1"     
    AND EXISTS (SELECT 'x' FROM B                                         
       WHERE B.PLANTYPE = A.PLANTYPE  AND B.PRODUCT = A.PRODSOLD)     


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
DB2/400 and DB2 UDB
Running source member SQL statements with RUNSQLSTM
Enabling IBM i to access Microsoft SQL server data
Using SQL to search within a DB2 field on IBM i
Controlling a library list on a remote system
Auditing: RPG with embedded SQL showing up as a changed object
Selecting a PF with multiple members from SQL
Referencing a renamed column on SELECT clause in SQL
Using WebSphere information integrator to access MS server data using SQLRPGLE
Joining files using SQLRPGLE
Querying system catalog tables to determine table alias

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



iSeries Networking - Printing, Remote Access, TCP/IP
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts