i m using sql 2000 and i have a table with 3 columns ( credit , debit, total)
what i want to do is whenever a value is inserted to the credit column it should add that amount to the total column and whenever there is a debit value it should Subtract from the total value
can some one please help me with this
i know this should be done by a rule but i cant figure out how to do it

Recommended Answers

All 3 Replies

Is Total supposed to be a running sum or is it simply the current total as reflected by the current credit and debit amounts?

In either case, I would look up triggers and modify your Total value whenever a row as updated.

it should be current total

it should be current total

The you can simply say

Update tableNameHere Set Total = Credit - Debit

As I said before, you should look up triggers in SQL Server 2000 to see how you can associate the aforementioned statement with a table as a record gets updated.

I assume there is a valid reason for storing a calculated value in the table when a simple query would do. I suppose that's just part of the assignment, huh?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.