phpmyadmin - sql查询错误

时间:2014-01-19 11:36:05

标签: mysql sql phpmyadmin

我一直在尝试执行以下查询而没有任何运气。它说:

  

#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$$

1 个答案:

答案 0 :(得分:0)

我错过了

DELIMITER ;

在查询结束时。添加了这个,一切正常。