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.
| 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_dateTransact Table:headid,vouid,damountHow 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] |
 |
|
|
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_date1 8/20/20082 8/21/20083 8/22/20084 8/23/20085 8/23/20086 8/24/2008headid vouid damount100 1 1000101 2 2000100 3 2500100 4 3000100 5 1500100 6 1500The Result of the head id is 1008/20/2008 10008/22/2008 35008/23/2008 80008/24/2008 9500 |
 |
|
|
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] |
 |
|
|
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 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-04 : 05:00:18
|
| Search for Running Total in this forumMadhivananFailing to plan is Planning to fail |
 |
|
|
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 t1INNER JOIN Table2 t2ON t2.vouid=t1.vouidGROUP BY t2.headid,t1.vou_date)SELECT c1.Date,c1.Amount + COALESECE(c2.PrevAmt,0) AS damountFROM CTE c1OUTER APPLY(SELECT SUM(Amount) AS PrevAmt FROM CTE WHERE Head=c1.Head AND Date <c1.Date) c2WHERE c1.Head=100[/code] |
 |
|
|
|
|
|
|
|