Ver Mensaje Individual
  #9 (permalink)  
Antiguo 21/09/2012, 10:31
Avatar de jlct
jlct
 
Fecha de Ingreso: abril-2012
Ubicación: Venezuela
Mensajes: 148
Antigüedad: 12 años, 11 meses
Puntos: 19
Respuesta: suma de dos valores en campos de una misma tabla

Solo tendrias que editar los trigger que escribi por ejemplo:

Supongo que tu tabla quetaria asi Stock(idsuministro,idsalidasuministro,stock);

entonces los trigger quedarian asi:

Create Trigger tg_suma_stock before insert on suministros
for each row
begin
declare stock_actual int;
set stock_actual = (Select Max(stock) from stock);
set stock_actual = stock_actual + new.unidadesentrantes;
update stock set stock=stock_actual where idsuministro=new.idsuministro;
end

Create Trigger tg_resta_stock before insert on salida_suministros
for each row
begin
declare stock_actual int;
set stock_actual = (Select Max(stock) from stock);
set stock_actual = stock_actual - new.unidaddesalida;
update stock set stock=stock_actual where idsalidasuministros = new.idpedidos;
end

Implementalo y cuentas que tal te va!!