MySQL Forums
Forum List  »  PHP

Display Query Result
Posted by: ibrahim sulyman
Date: May 15, 2015 12:11PM

I am trying to get information from 3 table using stored procedure, do some math and display the the result in 1 column. The tables as following;

RaisedFund: fundId, raiser, totalRaised
raiser is FK link to a other table.

payment: payId, payer, pdate, howMuch
payer is FK link to other table.

expenses: expenseId, spender, itemBought, cost
spender is FK link to the same table as raiser in RaisedFund.

I want to sum the total raised and howMuch paid and get the total income of both.
Then sum the cost to get the total spend.
Finaly take off the total spend from total income.

I have tried this code but the result was Null.

CREATE DEFINER=`root`@`localhost` PROCEDURE `netIncome`(IN OfficeId int,
OUT MemPayment decimal,
OUT TotalExpenses decimal,
OUT Total decimal,
OUT Remaining decimal)

BEGIN

declare count decimal;

Select sum(Cost) into TotalExpenses
from expenses where spender = OfficeId;

select sum(totalRaised) into Total
from RaisedFund where raiser = OfficeId;

select sum(howMuch) into MemPayment;

SET count = Total + Mempayment;

SET Remaining = count - TotalExpenses;


END

CALL netIncome( 1, @Remaining);
SELECT @Remaining AS NetIncome;

The result is NetIncome column but value is Null.

Options: ReplyQuote


Subject
Written By
Posted
Display Query Result
May 15, 2015 12:11PM
June 01, 2015 01:32PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.