Your original stmt updates all records in j.
Therefore when the condition was not met, j.act_time_id was being set to null.
Try this one:
(Check for syntax errors)
update DB2ADMIN.DW_RKEM_EQUIP_ACTIVITY_TBL_C j
set j.act_Time_id = (select case
when j.acttime = s.time_value and j.act_time_id <> s.time_id then
s.TIME_ID
else j.act_Time_id
end)
from DB2ADMIN.REF_TIME_LU_TBL s
);
Another approach will be -
update DB2ADMIN.DW_RKEM_EQUIP_ACTIVITY_TBL_C j
set j.act_Time_id = (select s.TIME_ID from DB2ADMIN.REF_TIME_LU_TBL s
where j.acttime = s.time_value and j.act_time_id <> s.time_id)
where <preidcate>
;
The predicate when applied should exclude all rows in j, that do not meet 'j.acttime = s.time_value and j.act_time_id <> s.time_id'
HTH
Sathyaram
Quote:
|
Originally Posted by JDionne
I have a complex update statment with a complex where clause. The code is as follows
Code:
update DB2ADMIN.DW_RKEM_EQUIP_ACTIVITY_TBL_C j
set j.act_Time_id = (select s.TIME_ID from DB2ADMIN.REF_TIME_LU_TBL s
where j.acttime = s.time_value and j.act_time_id <> s.time_id);
I am getting the following error:
Code:
update DB2ADMIN.DW_RKEM_EQUIP_ACTIVITY_TBL_C j set j.act_Time_id = (select s.TIME_ID from DB2ADMIN.REF_TIME_LU_TBL s where j.acttime = s.time_value and j.act_time_id <> s.time_id)
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0407N Assignment of a NULL value to a NOT NULL column "TBSPACEID=25,
TABLEID=11, COLNO=1" is not allowed. SQLSTATE=23502
The odd thing about this is that if I run the follwoing code I get a return:
Code:
select count(*) from DB2ADMIN.REF_TIME_LU_TBL s, DB2ADMIN.DW_RKEM_EQUIP_ACTIVITY_TBL_C j
where j.acttime = s.time_value and j.act_time_id <> s.time_id
I have checked the reference table for null values, and the base table cant have nulls because i am updating a key column. Dose anyone have any ideas what I am doing wrong?
|