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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Plz help me out

Author  Topic 

poornima
Starting Member

32 Posts

Posted - 2006-10-24 : 04:26:18
Hello

I have a table containing credit,debit,balance columns.Initially balance column has some value.Now if in credit column some value is entered,it should get added in the balance ,similarly if debit column has some value it should get subtracted.How do i manipulate this.

Thanks In Advance
Poornima

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-24 : 04:36:26
Can you post the table structure?

Madhivanan

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

mr_mist
Grunnio

1870 Posts

Posted - 2006-10-24 : 04:47:25
I reckon that you may be making life hard for yourself by storing the balance in the same table as credits and debits. Each credit and debit line should be a row in a seperate table, probably linked to the other table by customer ID.

-------
Moo. :)
Go to Top of Page

poornima
Starting Member

32 Posts

Posted - 2006-10-24 : 04:49:53
The below one is the table structure,but here i have manually entered the balance.I want to get it updated by setting the formula.Also i want to change the date format.


SNo Date Reason Credit Debit balance
1 1905-06-16 00:00:00.000 Salary 5000.00 0.00 5000.00
2 1905-06-15 00:00:00.000 Salary 5000.00 0.00 10000.00
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-24 : 04:59:15
A balance that goes back in time?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-24 : 05:01:59
See my answer about date format here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=73952
Also crossposting here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=73956


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-24 : 05:05:25
[code]SELECT q.SNo,
CONVERT(varchar, q.Date, 102) Date,
q.Reason,
q.Credit,
q.Debit,
(SELECT SUM(x.Credit - x.Debit) FROM MyTable x WHERE x.Date <= q.Date) Balance
FROM MyTable q[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -