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

33 lines
819 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`expeditionGetFromRoute`(
vExpeditionFk INT)
BEGIN
/**
* Get all expeditions from route
*/
DECLARE vRouteFk INT DEFAULT 0;
SELECT t.routeFk INTO vRouteFk
FROM vn.expedition exp
INNER JOIN ticket t on t.id = exp.ticketFk
WHERE exp.id = vExpeditionFk;
SELECT exp.id,
exp.ticketFk,
t.routeFk,
t.packages bultos,
ts.alertLevel,
a.street,
a.city,
a.postalCode,
a.id addressFk,
w.name warehouse
FROM vn.expedition exp
INNER JOIN ticket t ON t.id = exp.ticketFk
INNER JOIN vn.ticketState ts ON ts.ticketFk = exp.ticketFk
LEFT JOIN vn.address a ON t.addressFk = a.id
LEFT JOIN vn.warehouse w ON t.warehouseFk = w.id
WHERE t.routeFk = vRouteFk AND exp.freightItemFk > 0;
END$$
DELIMITER ;