SET TERM ^ ;

CREATE trigger ttbapi_integracao_agend_b02i for tbapi_integracao_agendamento
active before insert position 9
AS
declare variable HISTORICO VARCHAR(500);
begin
    HISTORICO = '';

    IF(NEW.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' AGENDAMENTO INCLUÍDO: '||NEW.ID;
    END

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

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbapi_integracao_agend_bd9 for tbapi_integracao_agendamento
active before delete position 9
AS
declare variable HISTORICO VARCHAR(500);
begin
    HISTORICO = '';

    IF(OLD.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' AGENDAMENTO EXCLUÍDO: '||OLD.ID;
    END

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

SET TERM ; ^

