CREATE OR ALTER TRIGGER TTBREQUISICAO_OC_ITEM_B1U FOR TBREQUISICAO_OC_ITEM
INACTIVE BEFORE UPDATE POSITION 1
AS
begin

   if (new.flag <> 1) then
   begin

      if (new.licitacao_id is not null) then
      begin
    
        IF (old.licitacao_id > 0) THEN
        BEGIN
    
            exception "..." 'O item de ID:'||old.id||' ja tem uma licitacao de ID:'||old.licitacao_id;
            New.id = New.requisicao_id;
        END ELSE
        IF (UPDATING) THEN
        BEGIN
          --if (new.valor <> old.valor) then
          --    new.valor2 = new.valor;
        END
    
      end
    end

end
