CREATE OR ALTER trigger ttbnfs_item_b10iu for tbnfs_item
active before insert or update position 9
AS
BEGIN
    IF(NEW.PEDIDO > 0 AND INSERTING) then
    BEGIN
        IF(NEW.VALOR_DESCONTO_ORIGINAL < NEW.VALOR_DESCONTO)THEN
        BEGIN
           EXCEPTION "..." 'ERRO AO CALCULAR VALOR DE DESCONTO ORIGINAL DO ITEM '||NEW.SEQUENCIA||'.';
           --NEW.VALOR_DESCONTO_ORIGINAL = NEW.VALOR_DESCONTO;
        END
    END

    IF(NEW.PEDIDO > 0 AND UPDATING) then
    BEGIN
        IF(NEW.VALOR_DESCONTO IS DISTINCT FROM OLD.VALOR_DESCONTO AND NEW.VALOR_DESCONTO_ORIGINAL < NEW.VALOR_DESCONTO)THEN
        BEGIN
           EXCEPTION "..." 'ERRO AO CALCULAR VALOR DE DESCONTO ORIGINAL DO ITEM '||NEW.SEQUENCIA||'.';
           --NEW.VALOR_DESCONTO_ORIGINAL = NEW.VALOR_DESCONTO;
        END
    END
END;