Home > Ask the AS/400 Experts > DB2/400 and DB2 UDB Questions & Answers > Error message of null values
Ask The iSeries 400 Expert: Questions & Answers
EMAIL THIS

Error message of null values

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: 17 August 2005
I keep getting the error message of null values not allowed in column or variable ZORD#T for SQL update (using V5R3):

UPDATE Z9519 A SET A.ZORD#T = (SELECT COALESCE( B.ZORD#T, A.ZORD#T ) FROM Z9517 B WHERE A.ZADES1 = B.ZADES1 AND A.WHS=B.WHS)

While I have no problem with the same tables, same SQL in V5R2 (I already set 0 to all numeric fields in table Z9519 before executing SQL update and all numeric fields in Z9517 are not NULL). Can you offer some suggestions as to why I'm having this problem?


>
In examining your statement, I noticed that you are not specifying selection (i.e. Where clause) on the update statement. As a result, you are requesting that every row in the Z9519 table be updated by DB2 as a result of this request. If the subselect does not produce a match for that row in Z9519, DB2 has to update to the null value (in which case the COALESCE function never even gets executed for that row, because the subselect didn't return a row).

If you want to update only a subset of the Z9519 rows (those that have a matching values for columns ZADESE1 and WHS) then you need to add that selection to the update statement:

UPDATE Z9519 A SET A.ZORD#T = (SELECT B.ZORD#T FROM Z9517 B WHERE A.ZADES1 = B.ZADES1 AND A.WHS=B.WHS) WHERE EXISTS (SELECT 'x' from Z9517 BB where A.ZADES1 = BB.ZADES1 AND A.WHS=BB.WHS)

OR

 UPDATE Z9519 A SET ZORD#T = 
  CASE 
    WHEN (SELECT B.ZORD#T FROM Z9517 B WHERE A.ZADES1 = B.ZADES1 AND A.WHS=B.WHS) IS NOT NULL 
      THEN(SELECT BB.ZORD#T FROM Z9517 BB WHERE A.ZADES1 = BB.ZADES1 AND A.WHS=BB.WHS) 
      ELSE A.ZORD#T 
   END 

==================================
MORE INFORMATION ON THIS TOPIC
==================================

Visit the ITKnowledge Exchange and get answers to your DB2 questions fast.

Check out this Search400.com Featured Topic: Expert advice on DB2

Search400.com's targeted search engine: Get relevant information on DB2/400.

The Best Web Links: Tips, tutorials and more.


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



RELATED CONTENT
DB2/400 and DB2 UDB
When is the YES option for 'reuse deleted files' function the best choice?
Monitoring members 'stuck' within a physical file on an EDI system
Developing tables in a parent-child relationship in DB2
SQL server error message -321
Creating a host variable of the 'where in' statement in SQL
Choose which column names are returned via ODBC when working with DB2 files
Allow access to data from a stored procedure result set using COBOL or RPG
Access path and an open data path differences
Convert a numeric physical file to a character in SQL without leading zeros
Inserting data from a CTE into a file in SQL

DB2 UDB (universal databases)
Oracle boasts 11g on SPARC is faster than IBM DB2 on Power 595
When is the YES option for 'reuse deleted files' function the best choice?
Monitoring members 'stuck' within a physical file on an EDI system
Developing tables in a parent-child relationship in DB2
SQL server error message -321
Creating a host variable of the 'where in' statement in SQL
Choose which column names are returned via ODBC when working with DB2 files
Access path and an open data path differences
Database performance comparisons on IBM i
Implement variables in SQL when creating an alias
DB2 UDB (universal databases) Research

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 technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




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