I'm trying to create a MySQL procedure to calculate tax. However it says that I have an error on line 9 involving the ')' token. Any idea how to fix it? Error message is:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT ((pSalary - taxExempt) * taxRate) INTO taxesDue; END' at line 27
My code is:
DELIMITER //
CREATE PROCEDURE calc_state_tax(
IN pSalary DECIMAL(9,2),
IN pStateCode VARCHAR(2),
IN pStatus VARCHAR(6),
OUT taxesDue DECIMAL(9,2)
)
BEGIN
DECLARE taxRate DECIMAL(7,5);
DECLARE taxExempt DECIMAL(9,2);
SELECT
s1.taxRate,
s1.exemptperfiler
INTO taxRate,taxExempt
FROM statetax s1
WHERE s1.statecode = CONCAT("'",pStateCode ,"'")
AND s1.type = CONCAT("'",pStatus,"'")
AND s1.bracket = (
SELECT MAX( s2.bracket )
FROM statetax s2
WHERE s1.statecode = s2.statecode
AND s1.type = s2.type
AND s2.bracket < pSalary )
SELECT ((pSalary - taxExempt) * taxRate) INTO taxesDue;
END; //
DELIMITER;
As my comment stated:
You're missing a semicolon after AND s2.bracket < pSalary )
I believe the problem is a missing semicolon on the immediately preceding line; it should look like so:
AND s2.bracket < pSalary );
See if that helps. Cheers!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.