GARANTIR DESCONTO

Fórum Trigger com multiplicação jogando em outro campo #59431

10/02/2008

0

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

Responder

Posts

11/02/2008

Djjunior

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


Responder

Gostei + 0

11/02/2008

Jpauloss

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


Responder

Gostei + 0

11/02/2008

Jpauloss

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?


Responder

Gostei + 0

11/02/2008

Jpauloss

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?


Responder

Gostei + 0

11/02/2008

Jpauloss

sobe


Responder

Gostei + 0

11/02/2008

Djjunior

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


Responder

Gostei + 0

11/02/2008

Jpauloss

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

Firebird 2.0


Responder

Gostei + 0

12/02/2008

Jpauloss

up


Responder

Gostei + 0

12/02/2008

Jpauloss

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


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar