2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`client_hasDifferentCountries`(vClientFk INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
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 ;
|