Fórum Trigger com multiplicação jogando em outro campo #59431
10/02/2008
0
CREATE TABLE LANCAMENTO_PROJETO ( ID_LANCAMENTO_PROJETO INTEGER NOT NULL, COD_PROJETO_LANCAMENTO VARCHAR(6), COD_GRUPO_FK INTEGER NOT NULL, COD_ORDENADO_M VARCHAR(20) NOT NULL, DESCRICAO_M VARCHAR(70), UN_M VARCHAR(2), PRECO_UNITARIO_M NUMERIC(15,2), QUANTIDADE_M VARCHAR(20), TOTAL NUMERIC(15,2), ITEM INTEGER );
To tentando criar uma trigger multiplicando o campo
PRECO_UNITARIO_M * QUANTIDADE_M
jogando esse resultado em TOTAL.
Comecei a fazer e ta assim
CREATE trigger qt_x_unitario for lancamento_projeto active after position 0 AS /* declare variable i integer; */ begin if (inserting) or (updating) then BEGIN for select quantidade_m, preco_unitario_m, total from lancamento_projeto where cod_projeto_lancamento=cod_projeto_lancamento begin total:=(quantidade_m) * (preco_unitario_m); end end end
Só que está dando esse erro
Invalid token. Dynamic SQL Error. SQL error code = -104. Token unknown - line 2, column 15. position.
Não tenho idéia de como resolver.
Alguma idéia?
Jpauloss
Curtir tópico
+ 0Posts
11/02/2008
Djjunior
se não me engano seria
CREATE trigger qt_x_unitario for lancamento_projeto
active after insert AS
begin
if (inserting) or (updating) then
total:=(quantidade_m) * (preco_unitario_m);
end;
end;
end
Gostei + 0
11/02/2008
Jpauloss
Vou testar
Gostei + 0
11/02/2008
Jpauloss
Não precisa do select?
Gostei + 0
11/02/2008
Jpauloss
CREATE trigger qt_x_unitario for lancamento_projeto active after insert or update as begin if (inserting) or (updating) then begin for select quantidade_m, preco_unitario_m, total from lancamento_projeto where cod_projeto_lancamento=cod_projeto_lancamento do begin update lancamento_projeto set total=(quantidade_m) * (preco_unitario_m) where cod_projeto_lancamento=cod_lancamento_projeto; end end end
Mas ta dando esse erro
Invalid token. Dynamic SQL Error. SQL error code = -104. Token unknown - line 5, column 18. or.
Que faço?
Gostei + 0
11/02/2008
Jpauloss
Gostei + 0
11/02/2008
Djjunior
Gostei + 0
11/02/2008
Jpauloss
Firebird 2.0
Gostei + 0
12/02/2008
Jpauloss
Gostei + 0
12/02/2008
Jpauloss
Alterei pra smallint.
Resolvido
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)