//修改库存表中的现存数量
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select * from RukuTmp');
ADOQuery1.Open;
//从入库临时表中查找所有数据
ADOQuery1.First;
while not ADOQuery1.Eof do
begin
ADOQuery2.Close;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Add('Select * from Kucun where ChID=:a');
ADOQuery2.Parameters.ParamByName('a').Value:=ADOQuery1.fieldbyname('ChID').AsString;
ADOQuery2.Open;
ADOQuery2.Edit;
ADOQuery2.FieldByName('Kcsl').AsFloat:=ADOQuery2.fieldbyname('Kcsl').AsFloat
+ADOQuery1.fieldbyname('Rksl').AsFloat;
ADOQuery2.Post;
ADOQuery1.Next;
end;
用SUM求和
with ADOQuery1 do
begin
close;
sql.clear;
sql.add('update Kucun set Kcsl = c.Kcsl from (select ChID,sum(Kcsl) as Kcsl from RukuTmp group by ChID) c, warehouse where Kucun.ChID =c.ChID ');
execsql;
end;