Triggers in SQL syntax issue in code SQL DB2 -
question:
my code works until reachs last line throws syntax error.
error :
db21034e command processed sql statement because not valid command line processor command. during sql processing returned: sql0104n unexpected token "temp_dept" found following "(case when ". expected tokens may include: "join". sqlstate=42601
i trying this:
- after each insert on rd_emp
- for each row
- insert rd_supervisor
- check cases, if temp_dept.rd_e_id <= 0 rd_supervisor.rd_e_sup 0
code:
create trigger rd_total_dep_emp \ after insert on rd_emp \ referencing new table temp_dept each statement \ insert rd_supervisor(rd_e_sup, rd_e_emp, rd_quot) \ select temp_dept.rd_e_id, (case \ when temp_dept.rd_e_id <= 0 0 \ when temp_dept.rd_e_id > 0 , temp_dept.rd_e_id <= 15 15 \ when temp_dept.rd_e_id > 15 , temp_dept.rd_e_id <= 25 25 \ when temp_dept.rd_e_id > 25 , temp_dept.rd_e_id <= 35 35 \ when temp_dept.rd_e_id > 35 100 \ end) rd_e_sup \ temp_dept
you have 3 columns in insert
, 2 in select
-- , appear in wrong order. following more intention:
create trigger rd_total_dep_emp \ after insert on rd_emp \ referencing new table temp_dept each statement \ insert rd_supervisor(rd_e_emp, rd_e_sup) \ select temp_dept.rd_e_id, (case \ when temp_dept.rd_e_id <= 0 0 \ when temp_dept.rd_e_id > 0 , temp_dept.rd_e_id <= 15 15 \ when temp_dept.rd_e_id > 15 , temp_dept.rd_e_id <= 25 25 \ when temp_dept.rd_e_id > 25 , temp_dept.rd_e_id <= 35 35 \ when temp_dept.rd_e_id > 35 100 \ end) rd_e_sup \ temp_dept
if there value want set rd_quot
, can specify -- both in insert
, select
.