Delphi下的SQL语句
Update 表 set ckzs=ckzs-'yzs' ,ckzl=ckzl-'yzl' where ID3='aID3'
ckzs有时候正常执行,但有时候整表被修改,整表的ckzs都被减去了'yzs' 而ckzl都能正常执行 不知是哪里出问题在线求解
Update 表 set ckzs=ckzs-'yzs' ,ckzl=ckzl-'yzl' where ID3='aID3'
ckzs有时候正常执行,但有时候整表被修改,整表的ckzs都被减去了'yzs' 而ckzl都能正常执行 不知是哪里出问题在线求解
入库没问题,就是这个出库修改问题
出库修改同时需要修改三张表
一张是出库表 表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要出问题是同时出问题,出问题的时候是电脑出现短暂卡机
不知为什么,每个月都会出现一到两次
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;粘贴后感觉有点乱
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语句
没用过这样的做法