Possible Duplicate:
Calculate a Running Total in SqlServer
I am creating a transaction table. Ive decided not to store the balance of each user anywhere. What I am plannign to do is, every month I will "BRING BALANCE FORWARD" and caclulate the balance from the balance bought forward MINUS debits PLUS credits.
My table looks like this
ID int primary key
userID int foriegn key
TransactionDate datetime
description varchar(200)
amount money
balanceBoughtForward bit
I am planning on writting a function that gets the latest record that is a balanceeboughtforward, then using that id to calculate the balance with the running total in a view with an extra column "BALANCE"
But I cant figure out how to create a running total column?