triggers - Store Mysql CASE select statement result in a variable -


i have following mysql trigger:

create trigger `upd_interim_final` after insert on `oee_main_interim`  each row insert `oee_main_interim_final` (id,name,ts,left_io,left_nio,recovery,right_io,right_nio,runmode,s_type,shift,std,curr_s_type)  values(null, new.name, new.ts, new.left_io, new.left_nio,  new.recovery, new.right_io, new.right_nio, new.runmode, new.s_type,     ( select    (case     when ((curtime() > oee_machinenames.shift1) ,     (curtime() < oee_machinenames.shift2)) 'shift1'     when ((curtime() > oee_machinenames.shift2) ,     (curtime() < oee_machinenames.shift3)) 'shift2'     when ((curtime() > oee_machinenames.shift3) or     (curtime() < oee_machinenames.shift1)) 'shift3' end) curr_shift   oee_machinenames      oee_machinenames.id = new.name  group   oee_machinenames.id),     (select     `std` `oee_variant` `machine_id` = new.name , `s_type` =   (select   `s_type`    `v_getmaxid`   `name` = new.name ,   v_getmaxid.max_id in (select     max(v_getmaxid.max_id) max_max_id       `v_getmaxid`       `name` = new.name))       , `oee_variant`.`operators` =      (select `operators` `oee_machinenames` `id` = new.name)),   (select   `s_type`    `v_getmaxid`   `name` = new.name ,   v_getmaxid.max_id in (select     max(v_getmaxid.max_id) max_max_id       `v_getmaxid`       `name` = new.name))    ) 

i trying store result of case clause in variable use later on in trigger:

 ( select        (case         when ((curtime() > oee_machinenames.shift1) ,         (curtime() < oee_machinenames.shift2)) 'shift1'         when ((curtime() > oee_machinenames.shift2) ,         (curtime() < oee_machinenames.shift3)) 'shift2'         when ((curtime() > oee_machinenames.shift3) or         (curtime() < oee_machinenames.shift1)) 'shift3' end) curr_shift           oee_machinenames              oee_machinenames.id = new.name      group       oee_machinenames.id), 

i have tried adding following beginning of trigger no success:

declare shifts text; set @shifts := ( select        (case         when ((curtime() > oee_machinenames.shift1) ,         (curtime() < oee_machinenames.shift2)) 'shift1'         when ((curtime() > oee_machinenames.shift2) ,         (curtime() < oee_machinenames.shift3)) 'shift2'         when ((curtime() > oee_machinenames.shift3) or         (curtime() < oee_machinenames.shift1)) 'shift3' end) curr_shift           oee_machinenames              oee_machinenames.id = new.name      group       oee_machinenames.id); 

any appreciated. thanks

@shifts 9.4. user-defined variables , shifts 1 13.6.4.1. local variable declare syntax, different variables.

here's example:

delimiter $$  drop procedure if exists `sp_test`$$  create procedure `sp_test`(`p_parm1` bool, `p_parm2` bool) begin     declare `shifts` char(6);     set `shifts` := (select case when `p_parm1` , `p_parm2` 'shift1'                                  when `p_parm1` , true 'shift2'                                  when true , `p_parm2` 'shift3'                                  else 'shift0'                             end                      dual                      true = true);     select `shifts`; end$$  delimiter ; 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -