TRIGGER que virifica o saldo e gera um exception

Firebird

11/10/2005

GALERA PRECISO DE UM TRIGGER QUE ANTES DE GRAVAR UM PEDIDO ELA VERIFICA UM LOTE E VE SE TEM SALDO

JÁ TENTEI FAZER ASSIM MAIS NEM TEM LOGICA
POIS ELE NÃO RECONHECE O IF QUE GERA O exception

ASSIM:
CREAT TRIGGER TESTE_SAIDA
ACTIVE BEFORE INSERT POSITION 0
AS
begin
if (new.cod_lotes > 0) then
begin
if (exists
(select indice from lotes
where indice = new.cod_lotes))
then begin
[color=red:fb203b37f6] if (lotes.saldo < new.peso_liquido) then exception LOTES_SAIDA;[/color:fb203b37f6] end
end
end


thanks e desde já agradeço


Marcos Fernando

Marcos Fernando

Curtidas 0

Respostas

Afarias

Afarias

11/10/2005

vc tem q fazer um select ... into para obter o valor de lotes.saldo


T+


GOSTEI 0
Marcos Fernando

Marcos Fernando

11/10/2005

Não seria algo assim:
mais não consigo executar a exception
CREATE TRIGGER ROMANEIO_SAIDA_BI0 FOR ROMANEIO_SAIDA
ACTIVE BEFORE INSERT POSITION 0
AS
declare variable s numeric(15,0);
begin
if (new.cod_lotes > 0) then
begin
for select indice from lotes_saida
where indice = new.cod_lotes
into :s do if ( :s < new.peso_liquido) then exception lotes_romaneio;
end
end


Thanks


GOSTEI 0
Beppe

Beppe

11/10/2005

Vc precisa criar a exception antes...create exception lotes_romaneio ´Alguma coisa deu errado!´


GOSTEI 0
Marcos Fernando

Marcos Fernando

11/10/2005

Na verdade eu mandava vir o INDICE e queria fazer referencia ao saldo,

já arrumei select SALDO e não Select Indice,

Grato amigo


GOSTEI 0
POSTAR