导入数据,判断与主键重复数据,重复的数据就更新原来的数据,不重复的数据就直接导入!
解决方案 »
- 怎样做拦截按钮的钩子?
- 简单的问题 -- 怎样调用外部程序
- 告急!delphi5怎样的到两个date值之间的完整的天数,要求返回整数,在线等!!
- 菜鸟问题,请帮忙。在线
- 关于树
- Query使用出现的这个错误:"Cannot modify a read-only dataset",怎么解决?(高分)
- 请问怎么样象资源管理器那样显示文件拷贝的进度??
- 求开发 ActiveX Libary 的详细步骤! Com Object 与 Automation Object 区别,如何用?
- SQLServer中如何存入大尺寸的图片???
- 如何取得数据类型的长度?
- 用Twriter 与TReader 对TMemoryStream操作出现错误,请帮忙
- FastReport打印图片的问题.
update ....
insert into ........
when not matched insert (colum_list) values(colum_values)
用这个就ok了,自己试试吧
set 数据库t2.dbo.表.字段 = 数据库t1.dbo.表.字段
from 数据库t2.dbo.表
where 数据库t1.dbo.表.id=数据库t2.dbo.表.idinsert into 数据库t2.dbo.表
select * from 数据库t1.dbo.表 where 数据库t1.dbo.表.id not in (select id from 数据库t2.dbo.表)
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from b where sfzh1 in (select sfzh1 from b group by sfzh1 having count(*)>1)');
adoquery1.Open;//选择重复记录 adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from b ');
adoquery1.Open;//选择所有记录 adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('delete from b where sfzh1 in (select sfzh1 from b group by sfzh1 having count(*)>1)');
adoquery1.ExecSQL;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from b ');
adoquery1.Open;//删除所有重复记录 adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('alter table b add idMytest int identity(1,1)');
adoquery1.ExecSQL; adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('delete from b where sfzh1 in (select sfzh1 from b where b.idMytest<idMytest '+
'group by sfzh1 having count(*)>1)');
adoquery1.ExecSQL; adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('alter table b drop column idMytest');
adoquery1.ExecSQL;//保留一条记录
var
AdoquerySource,Adoquery : Tadoquery; // Adoquerymd,
begin
try
AdoquerySource.Connection:=ADOConnection2;
// Adoquerymd.Connection:=ADOConnection3;
Adoquery.Connection:=ADOConnection3; AdoquerySource:=TAdoquery.Create(self);
// Adoquerymd:=TAdoquery.Create(self);
Adoquery:=TAdoquery.Create(self);
AdoquerySource.SQL.Clear;
AdoquerySource.SQL.Add('Select * from b');
AdoquerySource.Open;
while AdoquerySource.Eof do
begin
Adoquery.Close;
Adoquery.SQL.Clear;
Adoquery.SQL.Add('Select * from xxsqxmk where sfzh1=:sfzh1');
Adoquery.Parameters.ParamByName('sfzh1').Value:=AdoquerySource.fieldbyname('sfzh1').Value;
Adoquery.Open;
if Adoquery.RecordCount>0 then
begin
showmessage('已经存在')
end else
begin
//dosomething
end;
end;
finally
freeandnil(AdoquerySource);
freeandnil(Adoquery);
end;
end;
update tablename set ...
else
insert tablename ...
when not matched then insert (colum_list) values(colum_values)一句话就解决了,为什么还要那么多代码,那么复杂的过程来实现呢
关键是你写的SQL只能用于oracle,不通用阿。
using table2 别名2
on(join_condition)
when matched then
update set col1=value
when not matched then
insert (colum_list) values(colum_values)这个在oracle下是可以的,sql server2000下好些不行
set t2.b2= t1.b1
from t2,t1
where t1.t_id=t2.t_idinsert into t2
select * from t1 where t1.t_id not in (select t_id from t2)