输入单据时遇到有“编号”重复的商品怎样把它的“数量”相加后合成一条记录
-----------------------------------------------------------------------
你是指输入的时候自动处理吗?
还是用传统的sql语句吧
比如说你现在要输入的编号为10,数量为50,.......
定义一个新变量:
var
newcount: integer;
--------------------------
newcount := 0;
with ADOQuery1 do
begin
sql.clear;
sql.add('select * from table where no=10');
open;
if recordcount <> 0 then//已经存在
begin
newcount = 50+Fildbyname('count').asinteger;
//update 把原来的已经存在的数量改成现在的新数量
end
else//不存在
begin
//insert,作为新的一项插入到数据库
end;
end;