if (select count(*) from 表 where 编号='输入编号')=0 insert into 表(编号,名称,数量,单价)values(值,值,值,值) else update 表 set 数量=数量+值 where 编号='输入编号'
输入单据时遇到有“编号”重复的商品怎样把它的“数量”相加后合成一条记录 ----------------------------------------------------------------------- 你是指输入的时候自动处理吗? 还是用传统的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;
用sql很容易实现的
消除重复项用DISTINCT
合并项用SUM(字段);两者结合就可以了
insert into 表(编号,名称,数量,单价)values(值,值,值,值)
else
update 表 set 数量=数量+值 where 编号='输入编号'
-----------------------------------------------------------------------
你是指输入的时候自动处理吗?
还是用传统的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;