表中没有数据

时间:2018-11-12 07:16:20

标签: mysql

我试图根据查询将数据插入到表中,但是我得到的所有行都只为第一个字段(accountid)插入了数据,而其他字段为空!我在做什么错了?

DELIMITER $$
drop procedure if exists p_accounts_Totals2015;
$$
create procedure p_accounts_Totals2015()

BEGIN

    DECLARE l_last_row_fetched      INTEGER(1);
    DECLARE l_accountID             VARCHAR(30);
    DECLARE v_TotalDebits           FLOAT(13,2);
    DECLARE v_TotalCredits          FLOAT(13,2);
    DECLARE v_AccountDescription    VARCHAR(100);



    DECLARE c0 CURSOR FOR
        SELECT distinct AccountID
        FROM generalledgeraccounts2015
        WHERE GroupingCategory like 'GM';

    DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_last_row_fetched=1;     
    SET l_last_row_fetched=0;
    OPEN c0;
    c0_loop:LOOP
        FETCH c0 INTO l_AccountID;
        select gl.AccountDescription as v_accountdescription, 
               sum(td.debitamount) as v_TotalDebits
        from transactionsdebits2015 td, generalledgeraccounts2015 gl 
        where td.accountid=l_accountid and td.accountid=gl.accountid;
        INSERT INTO transactionstotals (AccountID, AccountDescription, 
                    TotalDebits)
        values (l_AccountID, v_accountdescription, v_TotalDebits);
        select gl.AccountDescription as v_accountdescription, 
               sum(tc.creditamount) as v_TotalCredits
        from transactionscredits2015 tc, generalledgeraccounts2015 gl 
        where tc.accountid=l_accountid and tc.accountid=gl.accountid;
        INSERT INTO transactionstotals (AccountID, 
                    AccountDescription,TotalCredits)
        values (l_AccountID, v_accountdescription ,v_TotalCredits);
        IF l_last_row_fetched=1 THEN
        LEAVE c0_loop;
        END IF;
    END LOOP;
    CLOSE c0;

END $$

0 个答案:

没有答案