Bill:

Time to learn 'Triggers'. But I see what you're doing.

Thanks again, Bill

Bruce
-------- Original Message --------
Subject: [RBASE-L] - Re: 'Running Total' Calculated Column
From: Bill Downall <[email protected]>
Date: Sun, April 15, 2012 1:00 pm
To: [email protected] (RBASE-L Mailing List)

Bruce,

The "same table" part makes it tricky, but you could use a trigger. This simplified version imagines that the sum is in a separate table. Otherwise you have to add logic to the trigger to avoid an endless loop, since it fires every time the table is updated, and it updates the same table. I'd have to look up Emmitt Dove's technique for aborting a trigger in that particular kind of self-referential situation.

{
to store this procedure and make it a trigger:
SET PROC CurrencySum LOCK ON
PUT CurrencySum.pro AS CurrencySum 'Retotal the Sum of stuff on updates'

ALTER TABLE BruceTable DROP TRIGGER UPDATE
ALTER TABLE BruceTable DROP TRIGGER INSERT
ALTER TABLE BruceTable DROP TRIGGER DELETE
ALTER TABLE BruceTable ADD TRIGGER +
  UPDATE CurrencySum, +
  INSERT CurrencySum, +
  DELETE CurrencySum
}

SET VAR vNewSum CURRENCY = NULL
SELECT SUM(CurrencyColumn) INTO vNewSum FROM BruceTable
UPDATE SumTable SET SumColumn = .vNewSum

RETURN

On Sun, Apr 15, 2012 at 12:32 PM, <[email protected]> wrote:
All:

rbase extreme 9.1.20410

How might one define a [currency | integer] computed column which records a current 'running total' for a target column (in the same table) for each newly-entered row?

The target column contains both positive and negatively signed values.

Or, is this best accomplished in table or view outside the target table?

Thanks much,

Bruce Chitiea
SafeSectors, Inc.

Reply via email to