salix/db/routines/vn/functions/client_hasDifferentCountrie...

22 lines
512 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`client_hasDifferentCountries`(vClientFk INT)
RETURNS tinyint(1)
NOT DETERMINISTIC
READS SQL DATA
BEGIN
/**
* Return if client have address in different countries.
*
* @param vClientFk The id client
* @return BOOL
**/
RETURN (SELECT COUNT(DISTINCT c.id) > 1
FROM `address` a
JOIN province p ON p.id = a.provinceFk
JOIN country c ON c.id = p.countryFk
WHERE a.clientFk = vClientFk
AND a.isActive);
END$$
DELIMITER ;