salix/db/routines/vn/procedures/routeInfo.sql

34 lines
768 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`routeInfo`(vRouteFk INT)
BEGIN
DECLARE vPackages INT;
DECLARE vM3 INT;
DECLARE vKg INT;
DECLARE vMatricula varchar(50);
SELECT sum(packages) as bultos
INTO vPackages
FROM vn.ticket t
WHERE routeFk = vRouteFk;
SELECT SUM(sv.physicalVolume), SUM(sv.physicalWeight)
INTO vM3, vKg
FROM vn.saleVolume sv
WHERE sv.routeFk = vRouteFk;
SELECT v.numberPlate as matricula
INTO vMatricula
FROM vn.route r
JOIN vn.vehicle v ON r.vehicleFk = v.id
WHERE r.id = vRouteFk;
SELECT vRouteFk as Ruta,
vPackages as Bultos,
vM3 as m3,
vKg as Kg,
vMatricula as Matricula;
END$$
DELIMITER ;