批量提交
update table1 set a=a+ b
from (select sum(b) b ,id from table2 group by id) h
where table1.id=h.id
insert into table1(....)
from (select sum(b) b ,id from table2 group by id) b left join table1
on b.id=table1.id
where table1.id is null
update table1 set a=a+ b
from (select sum(b) b ,id from table2 group by id) h
where table1.id=h.id
insert into table1(....)
from (select sum(b) b ,id from table2 group by id) b left join table1
on b.id=table1.id
where table1.id is null
解决方案 »
- 关于关键字EXISTS
- 从第 m 条到第 n 条记录的方法 不会用不懂...
- 存储过程里面我要把字符串名称"Progress32"拆分出来一个数字3,一个数字2.怎么弄?
- 求句SQL语句,在线等,有关时间类型的.
- 数据库本地与远程处理,求思路!
- 能不能判断出游标是取第一行?知道的请告诉我答案
- 别人刚刚删除了我写了好几天的存储过程,还没有备份,如何恢复,救命啊!
- 在SQLServer中如何批量生成以如下表的记录为名称的数据库?
- 一个SQL语句的问题
- 如何对一张表里的一个字段进行按周或按季度求和统计!100分啊
- 请问如何得到identity值?
- 难写的select语句:查出每个班级里身高最高的5个学生??
update段和insert段是在一起的吗?能智能识别修改还是添加吗?
我是用Delphi从XML数据文件中提出大量记录后对数据库进行修改或添加,你那儿有相关的例程吗?能否给我一份?
UPDATE在前(修改存在的),INSERT INTO 在后(左连接,插入表中不存在的记录)
这里循环读你的clientdataset中xml的记录
如:
while not clientdatasetXML.eof do
beign
clientdatasetSQL.append();
clientdatasetSQL.fieldbyname('XX').values=clientdatasetXML.fieldbyname('XX').values;
...
clientdatasetSQL.post();
clientdatasetXML.next();
end最后在这里clientdatasetSQL.applyupdate(0);
set col1=tabtmp.col1,col2tabtmp.col2...
from tabtmp
where tab.keyfield=tabtmpyfieldinsert into tab(...)
select * from tabtmp
where not exists (
select 1 from tab where
where tab.keyfield=tabtmpyfield
)
非常感谢你的这段代码,但只是解决了添加记录,而我的问题是XML中的记录如果数据库中有就修改、没有则添加,关键字段是nID,再帮忙考虑一下!