[英]What's wrong with my SQL code? Getting an error on last line
I'm trying to create a MySQL procedure to calculate tax. 我正在尝试创建一个MySQL过程来计算税收。 However it says that I have an error on line 9 involving the ')' token.
但是它说我在第9行有一个涉及')'标记的错误。 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 )
您在
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 );
AND s2.bracket <pSalary);
See if that helps. 看看是否有帮助。 Cheers!
干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.