Procedure in php mysql 5

<?php

– 
Account Balance Stored Procedure

DROP PROCEDURE IF EXISTS Account_Balance;

DELIMITER |
CREATE PROCEDURE Account_Balance (IN account_id INT,
 
IN before_date DATE)
BEGIN
    
DECLARE acct_creditacct_debitbalance INT;

    SELECT 
        SUM
(t.amountINTO acct_credit
    FROM 
        trxn 
AS t
    WHERE
        t
.credit_account_id account_id
      
AND
        
t.date <= before_date
    ORDER BY
        t
.created DESCt.trxn_id ASC;

    SELECT 
        SUM
(t.amountINTO acct_debit
    FROM 
        trxn 
AS t
    WHERE
        t
.debit_account_id account_id
      
AND
        
t.date <= before_date
    ORDER BY
        t
.created DESCt.trxn_id ASC;

    SET balance acct_debit acct_credit;
    
SET balance IFNULL(balance,0);

    SELECT balance;
END;
|
DELIMITER ;
?>

Tinggalkan Balasan