CREATE OR ALTER TRIGGER TTBNFS_ITEM_B1U FOR TBNFS_ITEM
ACTIVE BEFORE UPDATE POSITION 1
AS
begin

  if (Coalesce(Old.Margem,0) <> Coalesce(New.Margem,0)) then
      Begin
      NEW.MARGEM_DATAHORA = CURRENT_TIMESTAMP;
      End

  if(old.VALOR_DESCONTO_ORIGINAL is distinct from new.VALOR_DESCONTO_ORIGINAL
  and COALESCE(new.valor_desconto_original,0) < new.VALOR_DESCONTO)then
  begin
     EXCEPTION "..." 'ATENCAO, PEDIDO JA FATURADO. <BR> NOVO DESCONTO R$ '||cast(COALESCE(new.valor_desconto_original,0) as numeric(18,2))||' NAO PODE SER MENOR QUE O DESCONTO ANTERIOR R$ '||cast(COALESCE(new.valor_desconto,0) as numeric(18,2))||'!.';
  end
end