DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn2008`.`cc_to_iban`(cc VARCHAR(20)) RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci DETERMINISTIC BEGIN DECLARE iban VARCHAR(4); select CONCAT('ES', RIGHT( concat(0, 98- mod( concat( mod( concat( mod( concat( mod( substring(cc,1,8), 97), substring(cc,9,8) ), 97), substring( concat( cc, 142800 ), 17, 8 ) ), 97), substring( concat( cc, 142800 ), 25, 2 ) ), 97) ) ,2) )into iban; RETURN iban; END$$ DELIMITER ;