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 |
|
Ronesh
Starting Member
33 Posts |
Posted - 2009-09-02 : 01:06:15
|
| declare @table1 table ([date] datetime,particular varchar(15),debit money,credit money)insert into @table1values('2001/01/02','test',null,1000)insert into @table1values('2001/01/02','test',100,null)insert into @table1values('2001/01/02','test',null,500)insert into @table1values('2001/01/03','test',1000,null);WITH tempAS(SELECT row_number() OVER (ORDER BY [date]) AS [ID], * FROM @table1)SELECT [date] AS 'Trandate', particular, debit, credit, (SELECT SUM( -ISNULL(t2.debit,0) + ISNULL(t2.credit,0)) AS 'Balance'FROM temp t2WHERE t2.[ID] <= t1.[ID]) AS BalanceFROM temp t1TranDate particular debit credit Balance2001-01-02 00:00:00.000 test NULL 1000.00 1000.002001-01-02 00:00:00.000 test 100.00 NULL 900.002001-01-02 00:00:00.000 test NULL 500.00 1400.002001-01-03 00:00:00.000 test 1000.00 NULL 400.00looking forward for positive response. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-02 : 07:03:20
|
| Post your question in www.mysql.comMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|