Subject Doubt with trigger before insert
Author Andrei Luís
Hi,

FB 2.5.1 64bits running on Windows 7 64bits

I'm a little confused about how before insert triggers work.

I'm creating a before insert trigger to do some calcs at table order_items.

The problem is that the select that should bring the data from some tables,
is returning null. If I run the same select out of from the trigger (and
after it has been shot) I got the correct data. It seems to me it is
something related to transactions?

Below is a part of the trigger I'm mounting. The calculation new.subtotal =
new.qtde * new.valor works. The insert works too, but the fields after the
Select are getting null values.

Any clue?

SET TERM ^ ;

CREATE OR ALTER TRIGGER NOTASFISCAISITENS_BI0 FOR NOTASFISCAISITENS
ACTIVE BEFORE INSERT POSITION 0
as
declare variable wbaseicm dinheiro;
declare variable wcfoptemp integer;
declare variable wnatureza_temp varchar(80);
declare variable wnrnf_temp integer;
declare variable wcliente_temp varchar(100);
declare variable wuf_temp char(2);
declare variable wncm_temp integer;
begin
new.subtotal = new.qtde * new.valor;
insert into new_table (nfi_id) values (new.registro_id);
Select n.baseicm, n.registro_id, n.descricao, nf.nrnf, a.nome, uf.sigla,
cf.codfiscal
from notasfiscaisitens nfi
left join pedidositens pi on pi.registro_id = nfi.pedidoitem_id
left join orcamentos o on o.registro_id = pi.orcamento_id
left join produtos p on p.registro_id =
nfi.produto_id
left join notasfiscais nf on nf.registro_id =
nfi.notafiscal_id
left join naturezas n on n.registro_id =
nf.natureza_id
left join agenda a on a.registro_id = nf.cliente_id
left join uf on uf.sigla=a.uf
left join classificacaofiscal cf on
cf.registro_id=p.classificacaofiscal_id
where nfi.registro_id=new.registro_id
into :wbaseicm, :wcfoptemp, :wnatureza_temp, :wnrnf_temp,
:wcliente_temp, :wuf_temp, :wncm_temp;
new.cfop_temp = :wcfoptemp;
new.natureza_temp = :wnatureza_temp;
new.desconto = (new.Valor) * (:wdescontopercentual/100);
new.nrnf_temp = :wnrnf_temp;
new.cliente_temp = :wcliente_temp;
new.uf_temp = :wuf_temp;
new.ncm_temp = :wncm_temp;


end
^


SET TERM ; ^

[]s
Andrei


[Non-text portions of this message have been removed]