SET TERM ^ ;

CREATE trigger ttbcliente_situacao_b01i for tbcliente_situacao
active before insert position 0
AS
   DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( NEW.ID IS NOT NULL) THEN
    BEGIN
        HISTORICO = HISTORICO||'ITEM INCLUIDO: '||NEW.ID;
    END

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

SET TERM ; ^


SET TERM ^ ;

CREATE trigger ttbcliente_situacao_b01d for tbcliente_situacao
active before delete position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( OLD.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'ITEM EXCLUIDO: '||OLD.ID;
    END

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

SET TERM ; ^


SET TERM ^ ;

CREATE trigger ttbcliente_situacao_b01u for tbcliente_situacao
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

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

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

SET TERM ; ^





