Delphi下的SQL语句
Update 表 set ckzs=ckzs-'yzs' ,ckzl=ckzl-'yzl' where ID3='aID3'
ckzs有时候正常执行,但有时候整表被修改,整表的ckzs都被减去了'yzs'   而ckzl都能正常执行 不知是哪里出问题在线求解

解决方案 »

  1.   

    肯定不是这个语句的问题,你的程序另一个地方有个没有where,更新ckzs字段的语句
      

  2.   

    这个是仓库收发存系统
    入库没问题,就是这个出库修改问题
    出库修改同时需要修改三张表
    一张是出库表 表1
    一张是仓库表 表2
    一张是订单表 表3表1: Update 表1 set ckzs=ckzs-'yzs' ,ckzl=ckzl-'yzl' where ID2='aID2'
    表2: Update 表2 set ckzs=ckzs-'yzs' ,ckzl=ckzl-'yzl' where ID3='aID3'
    表3: Update 表3 set ckzs=ckzs-'yzs' ,ckzl=ckzl-'yzl' where ID1='aID1'
    表1从来不出问题
    表2和表3要出问题是同时出问题,出问题的时候是电脑出现短暂卡机
    不知为什么,每个月都会出现一到两次
      

  3.   

    小弟弱弱的问一句  ckzs=ckzs-'yzs'是什么意思?
      

  4.   

    procedure TJdxt_Data.ckxg(aID1, aID2, aID3, nID1, yCkzs, yckzl, aCkrq, aKh,
      aXh, aCd, aBh, aGuig, aBzxx, aCw, aCkbs, aCkzs, aCkzl, ach: OleVariant);
    var
      yf:string;  //库存表月份
      ID3:string;//库存表ID
    begin
        cxyf.Close;
        cxyf.Sql.Clear;
        cxyf.Sql.Add('select * from cxyf');
        cxyf.Open;
        yf:=cxyf.FieldByName('cxyf').AsString;    kcxg.Close;          //减去原库存  '这里要出问题,出问题后ckzs全是负数'
        kcxg.SQL.Clear;
       kcxg.SQL.Add('Update ck'+yf+' set ckzs=ckzs-'+yCkzs+',ckzl=ckzl-'+yCkzl+' where ID3='+aID3);
        kcxg.ExecSQL;    if  aID1<>'0' then
        begin
          Main_Detial.Close;  //减去原接单出库数  '这里要出问题,出问题后ckzs全是负数'
          Main_Detial.SQL.Clear;
          Main_Detial.SQL.Add('update Jd_Detial set ckzs=ckzs-'+yCkzs+',ckzl=ckzl-'+yckzl+' where ID1='+aID1);
          Main_Detial.ExecSQL;
        end;    kcxg.Close;         //查询修改后是否有库存
        kcxg.SQl.Clear;
        kcxg.SQL.Add('select * from ck'+yf+' where Xh='''+aXh+''' and cd='+aCd+' and  Bh='+aBh+' and Guig='''+aGuig+''' and Bzxx='''+aBzxx+''' and cw='''+aCw+'''');
        kcxg.Open;    if kcxg.RecordCount=0 then
        with cx do
        begin
          Close;
          SQL.Clear;
          SQL.Add('insert into ck'+yf+' values('''+aXh+''','+aCd+','+aBh+','''+aGuig+''','''+aBzxx+''','''+aCw+''',0,0,0,0,'+aCkzs+','+aCkzl+')');
          ExecSQL;
        end
        else if kcxg.RecordCount=1 then
        with cx do
        begin
          Close;
          SQL.Clear;
          SQL.Add('update ck'+yf+' set ckzs=ckzs+'+ackzs+',ckzl=ckzl+'+aCkzl+' where Xh='''+aXh+''' and cd='+aCd+' and  Bh='+aBh+' and Guig='''+aGuig+''' and Bzxx='''+aBzxx+''' and cw='''+aCw+'''');
          ExecSQL;
        end;    kcxg.Close;   //刷新
        kcxg.SQl.Clear;
        kcxg.SQL.Add('select * from ck'+yf+' where Xh='''+aXh+''' and cd='+aCd+' and  Bh='+aBh+' and Guig='''+aGuig+''' and Bzxx='''+aBzxx+''' and cw='''+aCw+'''');
        kcxg.Open;
        ID3:=kcxg.FieldByName('ID3').AsString;    //接单添加出库数
        if nID1<>'0' then with Main_Detial do
        begin
          Close;
          SQL.Clear;
          SQL.Add('update Jd_Detial set Ckzs=ckzs+'+aCkzs+',ckzl=ckzl+'+aCkzl+' where ID1='+nID1);
          ExecSQL;
        end;    //出库修改
        with ck do
        begin
          Close;
          SQL.Clear;
          SQL.Add('update ck set ID1='+nID1+',ID3='+ID3+',Ckrq='''+aCkrq+''',Kh='''+aKh+''',Xh='''+aXh+''',Cd='+aCd+',Bh='+aBh+',Guig='''+aGuig+''',Bzxx='''+aBzxx+''',Cw='''+aCw+''',ckbs='+ackbs+', Ckzs='+aCkzs+',Ckzl='+aCkzl+',ch='''+ach+''' where ID2='+aID2);
          ExecSQL;
        end;end;粘贴后感觉有点乱
      

  5.   


    kcxg.Close;          //减去原库存  '这里要出问题,出问题后ckzs全是负数'
    kcxg.SQL.Clear;
    kcxg.SQL.Add('Update ck'+yf+' set ckzs=ckzs-'+yCkzs+',ckzl=ckzl-'+yCkzl+' where ID3='+aID3);
    kcxg.ExecSQL;
    你在SQL.Add上打个点,按F8一直按,看看这个SQl语句
      

  6.   

    SQL 字符串能想减么~~
    没用过这样的做法
      

  7.   

    我们用的sql server 应该都不是正版的,反正正版的我没用过,很多时候sql server 会出一些奇怪的问题,所以做一些关键操作语句的时候多考虑一些情况,你的情况我遇到过,而且更奇怪的我也遇过。你的问题应该是空值或者关键字问题所造成的,在程序中增加一些检查和处理。