SET TERM ^ ;

CREATE OR ALTER trigger ttbempresa_biud998 for tbempresa
active before insert or update or delete position 998
AS
BEGIN

    IF(INSERTING) THEN
    BEGIN
        EXECUTE PROCEDURE SPI_INTEGRACAO('TBEMPRESA', NEW.CODIGO, 2);
    END ELSE
    BEGIN
        IF(NEW.RAZAOSOCIAL IS DISTINCT FROM OLD.RAZAOSOCIAL
        OR NEW.NOMEFANTASIA IS DISTINCT FROM OLD.NOMEFANTASIA
        OR NEW.CNPJ IS DISTINCT FROM OLD.CNPJ
        OR NEW.IE IS DISTINCT FROM OLD.IE
        OR NEW.IM IS DISTINCT FROM OLD.IM
        OR NEW.COMPLEMENTO IS DISTINCT FROM OLD.COMPLEMENTO
        OR NEW.BAIRRO IS DISTINCT FROM OLD.BAIRRO
        OR NEW.CEP IS DISTINCT FROM OLD.CEP
        OR NEW.CIDADE IS DISTINCT FROM OLD.CIDADE
        OR NEW.UF IS DISTINCT FROM OLD.UF
        OR NEW.EMAIL IS DISTINCT FROM OLD.EMAIL
        OR NEW.FONE IS DISTINCT FROM OLD.FONE
        OR NEW.CONTATO IS DISTINCT FROM OLD.CONTATO
        OR NEW.CELULAR IS DISTINCT FROM OLD.CELULAR
        OR NEW.DATA_ANIVERSARIO IS DISTINCT FROM OLD.DATA_ANIVERSARIO) THEN
        BEGIN
            EXECUTE PROCEDURE SPI_INTEGRACAO('TBEMPRESA', OLD.CODIGO, 2);

        END

    END
END
^

SET TERM ; ^

