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

Edited by __avd: Remove [color] [b] tags.

8 Years
Discussion Span
Last Post by apegram

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

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?

Edited by apegram: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.