Trigger com multiplicação jogando em outro campo

Firebird

10/02/2008

Tenho essa tabela
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

Jpauloss

Curtidas 0

Respostas

Djjunior

Djjunior

10/02/2008

isso é Oracle ?

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
Jpauloss

Jpauloss

10/02/2008

isso é Oracle ? 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

Vou testar


GOSTEI 0
Jpauloss

Jpauloss

10/02/2008

isso é Oracle ? 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

Não precisa do select?


GOSTEI 0
Jpauloss

Jpauloss

10/02/2008

Fiz assim
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
Jpauloss

Jpauloss

10/02/2008

sobe


GOSTEI 0
Djjunior

Djjunior

10/02/2008

essa trigger pra que SGBD ? (Oracle / sql server, ETC)


GOSTEI 0
Jpauloss

Jpauloss

10/02/2008

essa trigger pra que SGBD ? (Oracle / sql server, ETC)

Firebird 2.0


GOSTEI 0
Jpauloss

Jpauloss

10/02/2008

up


GOSTEI 0
Jpauloss

Jpauloss

10/02/2008

O problema estava com o campo quantidade VarChar(20), alterei com a ajuda de DonOctavioDelFlores.
Alterei pra smallint.
Resolvido


GOSTEI 0
POSTAR