Subject Re: [firebird-support] IS this the right thing to do (trigger)
Author Robert martin
Hi


> What is the frequency of running the counts query?
>
>
>

15 plus branches checking every 3 minutes. However when the DB gets
large and lots of other queries are running it can take 40+ seconds to
complete the sql.


>> And the following triggers to maintain totals....
>>
>
>
>> CREATE TRIGGER BranchSend_Edit FOR BranchSend
>> AFTER EDIT POSITION 10
>> AS BEGIN
>> IF (OLD.TransferConfirmed = 'F')
>> AND (New.TransferConfirmed = 'T') THEN
>>
>> UPDATE BranchSendCount
>> SET AvailableRecs = AvailableRecs - 1
>> WHERE RegionRef = NEW.RegionRef
>> AND SendTable = NEW.SendTable;
>>
>
> I think you really meant:
>
> SET AvailableRecs = AvailableRecs **+** 1
>
>
> Sean
>
>

Yes. Should have been

CREATE TRIGGER BranchSend_Edit FOR BranchSend
AFTER EDIT POSITION 10
AS BEGIN
IF (OLD.TransferConfirmed = 'F')
AND (New.TransferConfirmed = 'T') THEN

UPDATE BranchSendCount
SET AvailableRecs = AvailableRecs - 1
WHERE RegionRef = NEW.RegionRef
AND SendTable = NEW.SendTable;

IF (OLD.TransferConfirmed = 'T')
AND (New.TransferConfirmed = 'F') THEN

UPDATE BranchSendCount
SET AvailableRecs = AvailableRecs + 1
WHERE RegionRef = NEW.RegionRef
AND SendTable = NEW.SendTable;

END