Concatenate an SQL value

0

I have a trigger that updates a particular raw table, but it replaces the existing quantity and I need it to concatenate the new value with the existing value, could someone help me how to do this?

create trigger trg_atualizaEstmatprim after update on ped_pedidos
for each row
begin
declare vQntP int(11) default 0;
declare vNomeMP varchar(100);
if(new.ped_status = 'PEDIDO EM PRODUÇÃO') THEN
-- UPDATE est_estoque SET;
    select (ped_quantidade * prod_mat_prim_gasta) as total,  prod_nome_matprim  into vQntP, vNomeMP 
    from ped_pedidos pe inner join
    prod_produto p on p.prod_codigo = pe.pro_produto_pro_id where ped_codigo = old.ped_codigo;
    if(vQntP>0)then
        update est_matprim set est_quantidade = vQntP where est_matprim_mat_materiaprima = vNomeMP;
    end if;
END IF;
end

As you can see it gives an update overriding the value and I would like to concatenate it.

    
asked by anonymous 01.07.2017 / 23:22

1 answer

1

Your problem is that you are setting the value of est_quantidade to the value of vQntP , to make a join of the two, you should make a sum like this:

update est_matprim set est_quantidade = est_quantidade + vQntP where est_matprim_mat_materiaprima = vNomeMP;
    
01.07.2017 / 23:33