SET TERM ^ ;

ALTER TABLE TBCLIENTE ADD DISPOSICAO VARCHAR(100) CHARACTER SET UTF8 COLLATE UTF8 ^

CREATE OR ALTER TRIGGER TTBCLIENTE_B7U FOR TBCLIENTE
ACTIVE BEFORE UPDATE POSITION 9
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

   HISTORICO = '';

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

   IF (:HISTORICO <> '') THEN
       BEGIN
       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBEMPRESA', OLD.CODIGO,
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END^ 
SET TERM ; ^