salix/db/routines/vn/functions/supplier_getGeo.sql

26 lines
541 B
MySQL
Raw Normal View History

2024-11-14 08:27:38 +00:00
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`supplier_getGeo`(vSelf INT)
RETURNS int(11)
DETERMINISTIC
BEGIN
/**
* Returns the geo for the passed supplier.
*
* @param vSelf The address id
* @return The geo id
*/
DECLARE vGeoFk INT;
SELECT p.geoFk INTO vGeoFk
FROM supplier s
JOIN town t ON t.provinceFk = s.provinceFk
JOIN postCode p ON p.townFk = t.id
AND p.`code` = s.postCode
WHERE s.id = vSelf
ORDER BY (s.city SOUNDS LIKE t.`name`) DESC
LIMIT 1;
RETURN vGeoFk;
END$$
DELIMITER ;