Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Get balance to each day.

Author  Topic 

pentahari
Starting Member

26 Posts

Posted - 2008-09-03 : 02:52:32
how to sum the amount to each day.

Voucher Table:
vouid,vou_date

Transact Table:
headid,vouid,damount

How to get the date wise balance of the particular month.

Thanks Advance,
PentaHari

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-03 : 03:22:45
post some sample data and the expected result


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

pentahari
Starting Member

26 Posts

Posted - 2008-09-03 : 04:00:17
quote:
Originally posted by khtan

post some sample data and the expected result


KH
[spoiler]Time is always against us[/spoiler]




vouid vou_date
1 8/20/2008
2 8/21/2008
3 8/22/2008
4 8/23/2008
5 8/23/2008
6 8/24/2008


headid vouid damount
100 1 1000
101 2 2000
100 3 2500
100 4 3000
100 5 1500
100 6 1500


The Result of the head id is 100
8/20/2008 1000
8/22/2008 3500
8/23/2008 8000
8/24/2008 9500
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-03 : 04:02:12
SQL Server 2000 or 2005 ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

pentahari
Starting Member

26 Posts

Posted - 2008-09-03 : 04:04:18
quote:
Originally posted by khtan

SQL Server 2000 or 2005 ?


KH
[spoiler]Time is always against us[/spoiler]




2005
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-04 : 05:00:18
Search for Running Total in this forum

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-04 : 05:20:04
[code];With CTE(Head,Date,Amount) AS
(
SELECT t2.headid,t1.vou_date,SUM(t2.damount)
FROM Table1 t1
INNER JOIN Table2 t2
ON t2.vouid=t1.vouid
GROUP BY t2.headid,t1.vou_date
)

SELECT c1.Date,c1.Amount + COALESECE(c2.PrevAmt,0) AS damount
FROM CTE c1
OUTER APPLY(SELECT SUM(Amount) AS PrevAmt
FROM CTE
WHERE Head=c1.Head
AND Date <c1.Date) c2
WHERE c1.Head=100[/code]
Go to Top of Page
   

- Advertisement -