string MyInsert = "insert into QQ1 select name from QQ2 name not in ( select name from QQ1)";
*** NOT IN
insert into QQ1 select name from QQ2 where name not in ( select name from QQ1) 最好用 insert into QQ1 select name from QQ2 a where not exists not in ( select name from QQ1 b where a.name=b.name)
insert into QQ1 select name from (select name from QQ2 a where not exists (select name from QQ1 b where b.name = a.name))N
改成这样了,还是不行,还是把全码发上来,帮我诊断下吧 string constring = "server=192.168.1.11;database=daofeng;uid=DF;pwd=DAOFENG"; SqlConnection MyConnection = new SqlConnection(constring); MyConnection.Open(); string MyInsert = "insert into QQ1 select name from QQ2 a where not exists not in ( select name from QQ1 b where a.name=b.name) "; SqlCommand MyCommand = new SqlCommand(MyInsert, MyConnection); MyCommand.ExecuteNonQuery(); MyConnection.Close();
最好用
insert into QQ1 select name from QQ2 a where not exists not in ( select name from QQ1 b where a.name=b.name)
SqlConnection MyConnection = new SqlConnection(constring);
MyConnection.Open();
string MyInsert = "insert into QQ1 select name from QQ2 a where not exists not in ( select name from QQ1 b where a.name=b.name) ";
SqlCommand MyCommand = new SqlCommand(MyInsert, MyConnection); MyCommand.ExecuteNonQuery(); MyConnection.Close();
不好意思多写了个 not in