As you will see from my code, I've already specified the collation of my created table and the return of my function, yet I'm still getting the error message. Why is that ?
I'm getting the following error when applying my query in PHPmyAdmin-MYSQL: SQL query: UPDATE tb SET balance = (SELECT fnaccount_getbalance(acguid COLLATE utf8_general_ci,accur COLLATE utf8_general_ci,@stdate,@endate)) Error:
1267 - Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
Here is my Query:
CREATE TEMPORARY TABLE tb (id INT PRIMARY KEY AUTO_INCREMENT,
acguid char(38),
accur char(38),
account varchar(255),
debitsyp float,
creditsyp float,
balance float,
currency varchar(255))
CHARACTER SET utf8
COLLATE utf8_unicode_ci;
SET @stdate = '2011-01-01';
SET @endate = CURDATE();
INSERT INTO tb (acguid,accur,account,debitsyp,creditsyp,balance,currency)
SELECT ac.guid,ac.currencyguid,CONCAT(ac.code,'-',ac.name) AS account,0,0,0,my.code
FROM ac000 ac INNER JOIN my000 my ON ac.currencyguid = my.guid
WHERE ac.guid IN (SELECT accountguid FROM en000);
UPDATE tb SET debitsyp = (SELECT SUM(debit) FROM en000 WHERE accountguid = acguid);
UPDATE tb SET creditsyp = (SELECT SUM(credit) FROM en000 WHERE accountguid = acguid);
UPDATE tb SET balance = (SELECT fnaccount_getbalance(acguid,accur,@stdate,@endate));
SELECT * FROM tb;
And here is the code for my function fnaccount_getbalance:
BEGIN
DECLARE acbal float;
SET acbal = (SELECT IFNULL(SUM((CASE
WHEN currencyguid = accur THEN debit / currencyval
ELSE debit / fngetcurval(accur,endate)
END) -
(CASE
WHEN currencyguid = accur THEN credit / currencyval
ELSE credit / fngetcurval(accur,endate)
END)),0) as balance
FROM en000 WHERE accountguid = acguid
AND endate BETWEEN stdate AND endate);
RETURN (acbal COLLATE utf8_unicode_ci);
END