SET TERM ^ ;

CREATE OR ALTER trigger ttbpdv_devolucao_troca_biud998 for tbpdv_devolucao_troca
active before insert or update or delete position 998
AS
BEGIN

    IF(INSERTING) THEN
    BEGIN
        EXECUTE PROCEDURE SPI_INTEGRACAO('TBPDV_DEVOLUCAO_TROCA', NEW.ID, 2);
    END
    ELSE IF(UPDATING) THEN
    BEGIN
        IF(OLD.CLIENTE_ID IS DISTINCT FROM NEW.CLIENTE_ID OR
           OLD.VALOR_SALDO IS DISTINCT FROM NEW.VALOR_SALDO OR
           TRIM(OLD.TIPO_ED) <> TRIM(NEW.TIPO_ED)) THEN
           BEGIN
                EXECUTE PROCEDURE SPI_INTEGRACAO('TBPDV_DEVOLUCAO_TROCA', OLD.ID, 2);
           END

    END ELSE
    BEGIN
        EXECUTE PROCEDURE SPI_INTEGRACAO('TBPDV_DEVOLUCAO_TROCA', OLD.ID, 2);
    END

END
^

SET TERM ; ^

