var
  i, j: integer;
begin
  i := 1;
  j := 1;
  with ADOQuery1 do
    begin
      Clear;
      SQL.Clear;
      SQL.Add('SELECT * FROM TABLENAME');
      Open;    
      First;
      while not Eof do
        begin
          if (FieldByName('XNo').asinteger  Mod 10) <> 0 then
            begin
              Edit;
              FieldByName('DeviceNo').AsInteger := i;
              FieldByName('ButtonNo').AsInteger := j;
              Post;
              j := j + 1;
              if j > 3 then
                begin
                  j := 1;
                  i := i + 1;
                end
            end;
          Next
        end;
    end;
end;

解决方案 »

  1.   

    楼上的兄弟,你这种方法我也想到了,但是我的记录有2000多条,如果用这种方法,效率比较低,所以用Update了,呵呵,我想用Update该怎么写呢
      

  2.   

    update 表 set DeviceNo=ceiling(right(XNo,1)/3.0),ButtonNo=case right(XNo,1)%3 when 0 then 3 else right(XNo,1)%3
      

  3.   

    update 表 set DeviceNo=ceiling(right(XNo,1)/3.0),ButtonNo=case right(XNo,1)%3 when 0 then 3 else right(XNo,1)%3 end
    后面少了一个end.
      

  4.   

    谢谢你的回答,但是我用的是sqlite 好多函数支持不了,郁闷
      

  5.   

    drop table #tabTmp
    select iID=identity(int,1,1),XNo,DeviceNo=ceiling(right(XNo,1)/3.0),ButtonNo=case right(XNo,1)%3 when 0 then 3 else right(XNo,1)%3 end into #tabTmp from 表
    update 表 set DeviceNo=m.DeviceNo+ceiling(iID/10)*3,ButtonNo=m.ButtonNo from #tabTmp m where 表.XNo=m.XNo and 表.XNo % 10>0
    drop table #tabTmp