SET TERM ^ ;

CREATE OR ALTER trigger ttbcliente_999 for tbcliente
active before insert or update or delete position 999
AS
begin

  IF(OLD.SUFRAMA IS DISTINCT FROM NEW.SUFRAMA) THEN
  BEGIN
    EXECUTE PROCEDURE SPI_INTEGRACAO('TBEMPRESA', OLD.CODIGO, 2);
  END

  if(inserting)then execute procedure spi_integracao_mobile('TBCLIENTE',new.codigo,'I');
  if(updating )then execute procedure spi_integracao_mobile('TBCLIENTE',new.codigo,'A');
  if(deleting )then execute procedure spi_integracao_mobile('TBCLIENTE',old.codigo,'D');

  update tbreplica_tabela set Status = '0', Status_Qlik = '0'
  Where tabela = 'TBEMPRESA'
    and (Status = '1' or Status_Qlik = '1') ;

end
^

SET TERM ; ^

