Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear All create following procedure sp_summary to get sum of tables expences and collection's result into table balance which have column int expence, int collection, int balance but after execute above procedure i don't get values in balance table. Kindly help

ALTER procedure [dbo].[sp_summary]
AS BEGIN
Declare @coll as int
Declare @exp as int
Declare @tot as int

select @coll = SUM(amount) from expences
select @exp = SUM(amount) from collection
select @tot = @exp - @coll
insert into balance
values (@coll,@exp,@tot)
end
Posted

insert into balance (expense, collection, balance)
select (select sum(amount) from expenses), (select SUM(amount) from collection), (select SUM(amount) from collection) - (select SUM(amount) from expenses)

would work and doesn't need variables declaring (etc)...

looks naaaasty though...
 
Share this answer
 
Comments
Mahima Singh 22-Jun-15 10:44am    
Thanks dear it is working fine i display the report of balance in asp.net page but when i update to tables expenses,collection the report not update because i don't know how the same store procedure will execute automatically to update the values when page load or open so kindly reply how i call a store procedure in asp.net as per above example.
if your doing it in ASP, then rather than using a TSQL stored procedure to insert the values, wouldn't it be easier to get the values as variables in vb or whatever your language, and then create your stored procedure as a much simpler INSERT INTO statement with the values of the variables passed as parameters.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900