我要把数据表中的一个字段的某一个指定的值进行更新要怎么写SQL语句??  例如:在表‘图书信息’中的各个字段如下:
       图书编号     现存量    
        001        10
        002        10
   我要查找到图书编号为EDIT1里面输入的那个编号的现存量,再把现存量进行减1操作,然后再把数据表里面的现存量的数值更新为减1之后的数值,这个语句要怎么写??   各位帮帮忙!!拜托了,很急!!!

解决方案 »

  1.   

    例如:在表‘图书信息’中的各个字段如下:
           图书编号     现存量    
            001        10
            002        10
    update 图书信息  set 现存量=现存量-1 where 图书编号='001'
      

  2.   

    var
      Count:integer;
    with qry1 do
    begin
      close;
      sql.text:='select * from 图书信息 where 图书编号='''+edit1.text+'''';
      open;
      if not eof then
      begin
        Count:=fieldbyname('现存量').asinteger;
        close;
        sql.text:='update 图书信息 set 现存量='''+ inttostr(Count-1)+''' where 图书编号='''+edit1.text+''''; 
        ExecSQL;
      end;
    end;这是你想要的结果吗?
      

  3.   

    如果放两个Edit1,Edit2
    那么代码可以这样写
    with ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('update 图书信息  set 现存量='+Edit2.Text+'where 图书编号='+QuoteStr(Edit1.Text));
      Execsql; 
    end;
      

  4.   

    或者
    with qry1 do
    begin
      close;
      sql.text:='update 'update 图书信息 set 现存量=现存量-1 where 图书编号='''+ edit1.text+'''';
      ExecSQL;
    end;