CREATE OR ALTER TRIGGER TTBSUPERVISOR_B01U FOR TBSUPERVISOR
ACTIVE BEFORE UPDATE POSITION 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

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

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

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

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