SET TERM ^ ;

CREATE OR ALTER trigger tbcategoria_laclofit_bu0 for tbcategoria_laclofit
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( OLD.ID_ECOMMERCE <> NEW.ID_ECOMMERCE) THEN
    BEGIN
        IF(NEW.ID_ECOMMERCE = 0) THEN
            HISTORICO = HISTORICO||'ID ECM: '|| OLD.ID_ECOMMERCE||'->'||NEW.ID;
        ELSE
            HISTORICO = HISTORICO||'ID ECM: '|| OLD.ID_ECOMMERCE||'->'||NEW.ID_ECOMMERCE;
    END

    IF ( OLD.DESCRICAO <> NEW.DESCRICAO) THEN
    BEGIN
        HISTORICO = HISTORICO||' DESC: '|| OLD.DESCRICAO||'->'||NEW.DESCRICAO;
    END

    IF ( OLD.STATUS <> NEW.STATUS) THEN
    BEGIN
        HISTORICO = HISTORICO||' STATUS: '|| OLD.STATUS||'->'||NEW.STATUS;
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBCATEGORIA_LACLOFIT',NEW.ID,HISTORICO);
    END
end
^

SET TERM ; ^

