Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my table has following
SQL
sno      date           desc            amt       credit        debit  total 
2	08/02/2012	PURCHASE A/C	23	  34500.00	0.00		
2	08/02/2012	SOMU	23	0.00	  34500.00	NULL	
3	08/02/2012	SALES A/C	24	  0.00	        6000.00	NULL	
3	08/02/2012	DEVA	24	0	  0.00	        NULL	NULL
4	08/03/2012	SBI	14	0.00	  1000.00	NULL	NULL
4	08/03/2012	Cash A/c	14	  1000.00	0.00	NULL	
4	08/03/2012	Cash A/c	14	  1000.00	0.00	NULL	
4	08/03/2012	Cash A/c	14	  1000.00	0.00	NULL	


I want to sum of the Debit amount and Credit amount group by date how to do it?
SQL
sno      date           desc            amt       credit        debit  total 
2	08/02/2012	PURCHASE A/C	23	  34500.00	0.00		
2	08/02/2012	SOMU	23	0.00	  34500.00	NULL	
3	08/02/2012	SALES A/C	24	  0.00	        6000.00	NULL	
3	08/02/2012	DEVA	24	6000.00	  0.00	        NULL	NULL
4       08/02/2012      Total           null      69000         6000    null
5       08/02/2012      balance         null      9000          null    null
4	08/03/2012	SBI	14	0.00	  1000.00	NULL	NULL
4	08/03/2012	Cash A/c	14	  1000.00	0.00	NULL	
4	08/03/2012	Cash A/c	14	  1000.00	0.00	NULL	
4	08/03/2012	Cash A/c	14	  1000.00	0.00	NULL
5    08/03/2012        Total           null      4000          0.00	null
 6     08/03/2012       balance         null      4000          0.00    null 

How to get the total amount for order by date.
Thank you
Posted
Updated 3-Aug-12 5:11am
v3
Comments
Santhosh Kumar Jayaraman 3-Aug-12 7:06am    
u mean
1.get total debit and credit.
2. Get balance by subtracting total debit and credit
?
devausha 3-Aug-12 8:23am    
Yes you are correct. I got the total amount by using
sum(debit),sum(credit) group by reportdate.But i want display it next to the specify column like in questions, now all the total amount rows are displays last. How to set it under corresponding date.
Philip Stuyck 3-Aug-12 9:23am    
I don't quite understand what the result should look like, maybe you can provide an example of how the result of the query should look like.
devausha 3-Aug-12 11:06am    
I try to get the total debit and credit group by report date. And then I display that's like one row and the total is display next to the last row of the correspoding date like questions
Santhosh Kumar Jayaraman 3-Aug-12 12:08pm    
Check my solution

select date, sum(debit), sum(credit) from table
group by date
 
Share this answer
 
SQL
With CTE_Test
as
(select sno,[date],[desc],amt,creit,debit,Total,Row_number() over (PARTITION By date order by sno) as rowno
from temp_Table
union all
Select MAX(sno)+1,[date],'Total',null,SUM(creit),SUM(Debit),Null,1 from temp_table group by [date]
union all
Select MAX(sno)+2,[date],'Balance',null,SUM(creit)-SUM(Debit),null,Null,1 from temp_table group by [date])
Select * from cte_test order by date,sno
 
Share this answer
 
Comments
devausha 4-Aug-12 2:38am    
Thank you So much for your help. It is working nice.
Santhosh Kumar Jayaraman 4-Aug-12 2:40am    
Welcome

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