SET TERM ^ ;

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

    HISTORICO = '';

    IF ( OLD.UP_ID IS DISTINCT FROM NEW.UP_ID) THEN
    BEGIN
        HISTORICO = HISTORICO||'UP Alterada: '||OLD.UP_ID||' - > '||NEW.UP_ID;
    END

    IF ( OLD.GP_ID IS DISTINCT FROM NEW.GP_ID) THEN
     
        HISTORICO = HISTORICO||'TROCA DE GP: '||OLD.GP_ID||' - > '||NEW.GP_ID;
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBGP_UP',new.gp_id, HISTORICO);
    END

END
^

SET TERM ; ^

