Subject Re: Help with a trigger/procedure
Author Adam
--- In firebird-support@yahoogroups.com, "Fabio Gomes" <fabioxgn@...>
wrote:
>
> Nice,
>
> So what my procedure will look like?
>

Pretty close, sum returns null if no records exist (not sure why either).

select Coalesce(sum(qtde), 0) from table into :something;
delete from table;
insert into table (qtde) values (:something);

> Will just it work?

Yes.

To get the count, other transactions must run:

select Coalesce(sum(qtde), 0) from table

If the procedure has just run, it will only be summing a handful of
records. There is a trade-off at play. The more frequent you execute
the procedure, the less records to sum (so it runs faster). The
procedure does require resources to run, so you don't want to run it
unnecessarily.

Adam