表内数据合并
将表INPUT2中的字段total,quantity,wastweight内容加到表A中,规则表INPUT1。ID=INPUT2。INPUT1ID
我的语句如下
strSelect = "insert into input1 select total,quantity,wastweight from input2 where input2.input1id = (select id from input1)"
conn.Execute strSelect, i
我已在INPUT1中加入total,quantity,wastweight字段并且值都为NULL
报错:列名或所提供值的数目与表定义不匹配
问题点数:50、回复次数:7Top
1 楼meiqingsong(阿飛)回复于 2005-05-08 14:37:33 得分 5
可能是你input1表的列数不止三列,
或列顺序不对,
你把input1表的列名写出来试试。
strSelect = "insert into input1(列1,列2,列3) select total,quantity,wastweight from input2 where input2.input1id = (select id from input1)"
如果不是的话
可能是where input2.input1id = (select id from input1) 错了,
Top
2 楼xluzhong(Ralph)回复于 2005-05-08 14:40:20 得分 5
insert into input1
select total,quantity,wastweight
from input2 a
inner join input1 b
on a.input1id=b.id
Top
3 楼tdtjjiao(学习学习再学习)回复于 2005-05-08 14:46:21 得分 5
insert input1 (total,quantity,wastweight) select total,quantity,wastweight
from input2 where inputid = idTop
4 楼1410104(兔子)回复于 2005-05-08 14:49:20 得分 0
strSelect = "insert into input1(total,quantity,wastweight) select total,quantity,wastweight from input2 where input2.input1id = (select id from input1)"
报错:insert语句的选择列表包含的项多于插入列表中的项。SELECT语句中的值的数目必须与INSERT语句中的列的数目匹配。
我的INPUT1中有很多字段的
一开始作程序的时候是要求建二个表的,INPUT1和INPUT2,查询的时候要在INPUT1与INPUT2间建关联查询,可作完后发现可以直接将INPUT2的数据存在INPUT1中,于是想将现在INPUT2已存的数据存入INPUT1Top
5 楼xluzhong(Ralph)回复于 2005-05-08 14:56:48 得分 20
insert into input1(total,quantity,wastweight)
select total,quantity,wastweight
from input2 a
inner join input1 b
on a.input1id=b.idTop
6 楼1410104(兔子)回复于 2005-05-08 15:07:23 得分 0
strSelect = "update input1 set total=input2.total,quantity=input2.quantity,wastweight=input2.wastweight from input1 inner join input2 on input1.id=input2.input1id"
用这个语句实现了
还有想请教,INPUT1中还有个字段是ONEWEIGHT我想将每条记录中ONEWEIGHT的值*QUANTITY的值并保存到INPUT1中的QUANTITYWEIGHT字段中,字段QUANTITYWEIGHT已存在,并且都为NULL
如何写
Top
7 楼duanduan1122(俺村俺帅!!!)回复于 2005-05-08 17:12:10 得分 15
insert into input1(total,quantity,wastweight)
select total,quantity,wastweight
from input2 a
inner join input1 b
on a.input1id=b.id
Top




