26 lines
535 B
MySQL
26 lines
535 B
MySQL
|
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 ;
|