DROP function IF EXISTS `vn`.`ticketTotalVolume`; DELIMITER $$ USE `vn`$$ CREATE DEFINER=`root`@`%` FUNCTION `ticketTotalVolume`(vTicketId INT) RETURNS decimal(10,3) READS SQL DATA BEGIN -- Devuelte el volumen total del ticket sumado -- DECLARE vWarehouseId INTEGER; -- DECLARE vShippedDate DATE; DECLARE vVolume DECIMAL(10,3); /* SELECT warehouseFk, shipped INTO vWarehouseId,vShippedDate FROM vn.ticket WHERE id = vTicketId; SELECT IFNULL(SUM(s.quantity * i.compression * r.cm3)/1000000,0) INTO vVolume FROM sale s JOIN vn.item i ON i.id = s.itemFk JOIN bi.rotacion r on r.Id_Article = s.itemFk AND r.warehouse_id = vWarehouseId WHERE s.ticketFk = vTicketId; */ SELECT sum(volume) INTO vVolume FROM ticketGetVolume WHERE ticketFk = vTicketId; RETURN vVolume; END$$ DELIMITER ;