DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`entry_getCurrency`(vCurrency INT, vSupplierFk INT ) RETURNS int(11) NOT DETERMINISTIC READS SQL DATA BEGIN DECLARE vIsDollarAccount BOOL; SELECT account LIKE '___4______' INTO vIsDollarAccount FROM vn.supplier WHERE id = vSupplierFk; IF vIsDollarAccount THEN RETURN 2; ELSE RETURN vCurrency; END IF; END$$ DELIMITER ;