现在要将access库的两个表'人员1'和'人员2'中的数据导入到SQL数据库中的一个表tblRenyuan中.'人员1'和'人员2'是同样的人的不同字段的记录,前面已经把'人员1'数据导入tblRenyuan中了,现在想把这些人在"人员2"中的记录插入到tblRenyuan中. 尤其是adoquery2添加的SQL语句中,where条件怎么写?请教大家了.with adoquery1 do
begin
adoquery1.Close;
//adoquery1.Active;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 人员2');
//adoquery1.ExecSQL;
adoquery1.Open;
adoquery1.Active;
progressbar1.Max := adoquery1.RecordCount;
try
for j:=0 to adoquery1.RecordCount-1 do
begin
progressbar1.Visible :=true;
progressbar1.Position :=j;
with adoquery2 do
begin adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from tblRenyuan where '+adoquery2.FieldValues['03XM']+' = '+adoquery1.FieldValues['姓名']+'');
adoquery2.Open;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('insert into tblRenyuan([62ZYLL],[61JCLL]) values('''+adoquery1.FieldValues['专业理论']+''','''+adoquery1.FieldValues['基础理论']+''')');
adoquery2.ExecSQL;
adoquery2.Post;
begin
adoquery1.Close;
//adoquery1.Active;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 人员2');
//adoquery1.ExecSQL;
adoquery1.Open;
adoquery1.Active;
progressbar1.Max := adoquery1.RecordCount;
try
for j:=0 to adoquery1.RecordCount-1 do
begin
progressbar1.Visible :=true;
progressbar1.Position :=j;
with adoquery2 do
begin adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from tblRenyuan where '+adoquery2.FieldValues['03XM']+' = '+adoquery1.FieldValues['姓名']+'');
adoquery2.Open;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('insert into tblRenyuan([62ZYLL],[61JCLL]) values('''+adoquery1.FieldValues['专业理论']+''','''+adoquery1.FieldValues['基础理论']+''')');
adoquery2.ExecSQL;
adoquery2.Post;
insert tblRenyuan(字段)
select 字段 from 表1 left join 表2
表人员1的记录是:
姓名 成绩1李四 5
赵六 4
张三 3
王五 3姓名 成绩2张三 100
李四 80
王五 85
赵六 70现在想把这两个表中的这两个字段的记录全部导入SQL数据库中的tblRenyuan中,要求成绩要与每个人对应
姓名 成绩1 成绩2张三 3 100
李四 5 80
王五 3 85
赵六 4 70
with adoquery1 do
begin
close;
sql.clear;
sql.add('insert into tblrenyuan select a.姓名,a.成绩1,b.成绩2 from data1 a,data2 b
where a.姓名=b.姓名');
execsql;
end;
注意tblrenyuan的字段属性要跟DATA1,DATA2的对应字段属性设置一样。
update tblrenyuan set 成绩2=b.成绩2 from tblrenyuan a,人员表2 b
where a.姓名=b.姓名
update tblrenyuan set 成绩2=b.成绩2 from tblrenyuan a,人员表2 b
where a.姓名=b.姓名;