我一直在尝试执行以下查询而没有任何运气。它说:
#1064-您的SQL语法有误;检查手册
对应于您的MySQL服务器版本以使用正确的语法
在第32行的''附近
我无法指出任何错误。有人可以告诉我我在做什么错吗?
DELIMITER $$
--
-- Procedures
--
CREATE PROCEDURE `Acc_Ledger`(IN `startDate` VARCHAR(200), IN `endDate` VARCHAR(200), IN `p_id` INT)
BEGIN
DECLARE RunningTotal, deb, cred DECIMAL(19,2);
DECLARE counter, row_count int;
SET RunningTotal = 0;
SET counter = 1;
DROP TABLE IF EXISTS LedgerTbl;
CREATE TEMPORARY TABLE LedgerTbl (CTR int primary key auto_increment, PARTY_ID INT,VRDATE VARCHAR(200),VRNOA VARCHAR(200),ETYPE VARCHAR(50),DESCRIPTION VARCHAR(500),DEBIT DECIMAL(19,2),CREDIT DECIMAL(19,2),RTotal DECIMAL(19,2));
INSERT INTO LedgerTbl
SELECT null, PARTY_ID,VRDATE,DCNO,ETYPE,DESCRIPTION,DEBIT,CREDIT, null FROM pledger WHERE PARTY_ID=p_id AND DATE(VRDATE) BETWEEN startDate AND endDate
ORDER BY VRDATE,ETYPE,DCNO;
SET @RunningTotal := 0;
SELECT SUM(DEBIT)-SUM(CREDIT) FROM pledger WHERE DATE(VRDATE) < startDate AND party_id = p_id INTO @RunningTotal;
IF ISNULL(@RunningTotal) THEN
SET @RunningTotal := 0;
END IF;
UPDATE LedgerTbl
SET RTotal = (@RunningTotal := @RunningTotal + (DEBIT - CREDIT));
SELECT * FROM LedgerTbl;
END$$
最佳答案
我错过了
DELIMITER ;
在查询末尾。添加了这个,一切工作正常。