Hi All,
Having following two tables as
Code:
C:\Documents and Settings\db2admin>db2 select * from cl
ACC_NUM AMT
------------- -----------
AB112 27
AB113 47
AB114 87
AB115 37
AB116 97
AB117 67
AB118 87
AB119 77
8 record(s) selected.
C:\Documents and Settings\db2admin>db2 select * from tm
ACC_NUM AMT
------------- -----------
AB119 70
AB116 40
AB113 20
3 record(s) selected.
All columns defined as NOT NULL
SQL to update returns an Error
Code:
C:\Documents and Settings\db2admin>db2 update cl source set amt =
select amt from tm target where source.acc_num=target.acc_num)
DB21034E The command was processed as an SQL statement because
it was not avalid Command Line Processor command. During SQL
processing it returned:SQL0407N Assignment of a NULL value to
a NOT NULL column "TBSPACEID=4,TABLEID=530, COLNO=1" is
not allowed. SQLSTATE=23502
I undestand that the way I write statement is returning nulls.
Code:
UPDATE CL SOURCE SET
AMT = (
SELECT AMT FROM TM TARGET
WHERE SOURCE.ACC_NUM=TARGET.ACC_NUM
);
Please help me write correct update statement : Need to update table CL from table TM simply to set AMT as in TM table where ACC_NUM matches.
Thanks
DBFinder