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

26 lines
535 B
MySQL
Raw Normal View History

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