SET TERM ^ ;

CREATE OR ALTER trigger ttbremessa_b11d for tbremessa
active before delete position 0
AS
declare variable talao integer;
begin

  if(old.origem in (22600,22599))then
  begin
      talao = coalesce((SELECT FIRST 1 P.CONTROLE FROM TBPEDIDO_ITEM_PROCESSADO P WHERE P.REMESSA = old.numero),0);
    
      if(talao > 0)then
      begin
        exception "..." 'REMESSA ('||OLD.remessa||') NAO PODE SER EXCLUIDA, EXISTEM TALOES GERADOS.';
    
      end
    
      delete from tbremessa_acumulado a where a.remessa = old.numero;
  end

end
^

SET TERM ; ^

