21 lines
564 B
SQL
21 lines
564 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`orderTotalVolume`(vOrderId INT)
|
|
RETURNS decimal(10,3)
|
|
NOT DETERMINISTIC
|
|
READS SQL DATA
|
|
BEGIN
|
|
-- Devuelte el volumen total de la orden sumada
|
|
DECLARE vWarehouseId INTEGER;
|
|
DECLARE vVolume DECIMAL(10,3);
|
|
|
|
SELECT IFNULL(SUM(o.amount * ic.cm3delivery)/1000000,0) INTO vVolume
|
|
FROM hedera.orderRow o
|
|
JOIN item i ON i.id = o.itemFk
|
|
JOIN itemCost ic on ic.itemFk = o.itemFk AND ic.warehouseFk = o.warehouseFk
|
|
WHERE o.orderFk = vOrderId;
|
|
|
|
RETURN vVolume;
|
|
|
|
END$$
|
|
DELIMITER ;
|