我正在尝试创建一个MySQL程序来计算税收。但是它说我在第9行有一个涉及')'令牌的错误。知道怎么解决吗?错误信息是:
#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
我的代码是:
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;
答案 0 :(得分:2)
正如我的评论所说:
您在AND s2.bracket < pSalary )
答案 1 :(得分:1)
我认为问题是前一行上缺少分号;它应该是这样的:
AND s2.bracket&lt; pSalary);
看看是否有帮助。干杯!