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 > DB2 > DB2 sql - null values not allowed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Nov 2012
Posts: 2
DB2 sql - null values not allowed

Hello,

i need help with following update SQL:

update table1 a set a.IDPHNO = (select b.IRPHNO from table2 b where
a.IDSUNO = b.IRSUNO and b.IRSUNO <> '') where a.IDPHNO<> ''
-> Error: null values not allowed (ID SQL0407)

I also tried following:

update table1 a set a.IDPHNO = (select b.IRPHNO from
table2 b where a.IDSUNO = b.IRSUNO and b.IRPHNO <>'')
where exists
(select * from
table2 b where a.IDSUNO = b.IRSUNO and b.IRPHNO <>'')
-> more than one row (ID SQL0811)

Can someone help?
Thanks, Chatman
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Apr 2008
Location: Iasi, Romania
Posts: 478
There is a NOT NULL constraint defined on IDPHNO column. You may add to the WHERE clause:
AND b.IRPHNO IS NOT NULL
Of course, I do not know what your business requirements are.
__________________
Florin Aparaschivei
DB2 9.7 on Windows
Iasi, Romania
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Oct 2012
Posts: 11
Another way, if you want to update all records in your select criteria, is to use a case statement so that if b.IRPHNO is null, you return a dummy value.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Nov 2012
Posts: 2
not NULL

Hello, thanks for your feedback but i think this do not work to add NULL in query:

update table1 a set a.IDPHNO =
(
select b.IRPHNO from table2 b
where a.IDSUNO = b.IRSUNO and b.IRPHNO <> '' and b.IRPHNO is not NULL
)
where a.IDPHNO <> '' and a.IDPHNO is not NULL

Any idea?
Reply With Quote
  #5 (permalink)  
Old
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 5,396
If the subquery doesn't return any rows, your UPDATE statement will attempt to assign NULL to a.IDPHNO
__________________
---
"It does not work" is not a valid problem statement.
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