salix/db/routines/vn2008/procedures/compresTriggerBeforeInsert.sql

18 lines
566 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`compresTriggerBeforeInsert`(newNoVincular INT, newEntrada INT, newCompra INT, newItem INT)
BEGIN
DECLARE newWarehouse INTEGER;
IF newNoVincular = FALSE THEN
UPDATE travel t
JOIN vn.lastBuy lb ON newItem = lb.item AND t.warehouse_id = lb.warehouse
JOIN Entradas e ON e.travel_id = t.id
SET lb.id = newCompra
WHERE e.Id_Entrada = newEntrada AND t.landing > lb.landing AND t.landing <= util.VN_CURDATE();
END IF;
END$$
DELIMITER ;