22 lines
514 B
MySQL
22 lines
514 B
MySQL
|
DELIMITER $$
|
||
|
CREATE OR REPLACE DEFINER=`root`@`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 ;
|