22 lines
518 B
SQL
22 lines
518 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`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 ;
|