Running Balance Trigger Update

Hello,

With this Trigger :
ALTER trigger TRANSACTION_BALANCE
ON dbo.Transactions
FOR UPDATE, INSERT
AS
DECLARE @AccBalance money

BEGIN
UPDATE Transactions
      SET balance = (select sum(deposit) - sum(payment) FROM Transactions t2 where t2.TID <= Transactions.TID and t2.AccID = Transactions.AccID and t2.void = 0)
      FROM INSERTED i
      WHERE Transactions.AccID = i.AccID
      AND Transactions.TID >= i.TID
END


I'm trying to capture the last 'balance' value updated by the trigger, store it in a local variable, then insert that value in another table.  

I'm not sure how/whether to integrate these require within this trigger or to write another to handle that.  
this is what i need to do.

DECLARE @AccBalance money
INSERT Accounts(Balance, LastUpdated) values (@AccBalance, GETDATE())
WHERE Transactions.AccID = i.AccID

?


Thank-you
show_tAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ShogunWadeCommented:
It may be better to simply have a view over the Accounts & Transactions Table.  
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
show_tAuthor Commented:
I am aware of this, i'm currently using a sproc to update my Accounts table for the afore mentioned task.
But i'm trying to improve db performance and cut down on code.  

If i used a trigger, this would be so,

Thanks
0
show_tAuthor Commented:
Plus i try and use triggers more these days as i'm not very good at them...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.