0

Question:

My code works until it reachs last line then it throws a syntax error.

Error :

DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0104N An unexpected token "temp_dept" was found following "(case when ". Expected tokens may include: "JOIN". SQLSTATE=42601

I am trying to do this:

  • After each insert on RD_EMP
  • for each row
  • insert into RD_Supervisor
  • check for cases, if temp_dept.RD_E_ID <= 0 THEN RD_Supervisor.RD_E_SUP 0

Code:

create trigger RD_total_dep_emp \
after insert on RD_Emp \
referencing new table as temp_dept
for each statement \
   insert into RD_Supervisor(RD_E_SUP, RD_E_EMP, RD_QUOT) \
   select temp_dept.RD_E_ID, 
       (case \
         when temp_dept.RD_E_ID <= 0 then 0 \
         when temp_dept.RD_E_ID > 0 AND temp_dept.RD_E_ID <= 15 then 15 \
         when temp_dept.RD_E_ID > 15 AND temp_dept.RD_E_ID <= 25 then 25 \
         when temp_dept.RD_E_ID > 25 AND temp_dept.RD_E_ID <= 35 then 35 \
         when temp_dept.RD_E_ID > 35 then 100 \ 
        end) as RD_E_SUP \ 
   from temp_dept        

2 Answers 2

1

You have three columns in the insert, but only two in the select -- and they appear to be in the wrong order. The following is probably more your intention:

create trigger RD_total_dep_emp \
after insert on RD_Emp \
referencing new table as temp_dept
for each statement \
   insert into RD_Supervisor(RD_E_EMP, RD_E_SUP) \
       select temp_dept.RD_E_ID, 
           (case \
             when temp_dept.RD_E_ID <= 0 then 0 \
             when temp_dept.RD_E_ID > 0 AND temp_dept.RD_E_ID <= 15 then 15 \
             when temp_dept.RD_E_ID > 15 AND temp_dept.RD_E_ID <= 25 then 25 \
             when temp_dept.RD_E_ID > 25 AND temp_dept.RD_E_ID <= 35 then 35 \
             when temp_dept.RD_E_ID > 35 then 100 \ 
            end) as RD_E_SUP \ 
       from temp_dept

If there is a value you want to set for RD_QUOT, then you can specify that as well -- both in the insert and the select.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, that solved my problem after all these headaches.
1

You have an opening parenthesis before CASE, but you don't have a closing parenthesis after END.

https://xkcd.com/859/

1 Comment

Hi, I checked and put the extra bracket I still have an error thrown. I also edited my post and described what error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.