insert into table2 select from table1 where f1='xx' and f2='yy' ......and id not in (select id from table2)

解决方案 »

  1.   

    通常: of123() (说的是相同的表结构前提下,
    如果表结构不同,那么就要编一个小程序实现了
    你说这种SQL语句好项写不出来吧
      

  2.   

    dim rs1,cn,rs2,sqlstring1,sqlstring2
    ...
    cn.open connectionstring
    sqlstring1="select * from tabel1"
    rs1.open sqlstring1,cn,1,1
    do while not rs1.eof
      sqlstring2="insert into tabel2(col1,col2,col3,col4...) values('" & rs1.fields("col1") & "','" & rs1.fields("col2") & "'...)"
      rs2.open sqlstring2,cn,1,1
      'cn.execute sqlstring2
    rs1.movenext
    loop
      

  3.   

    重新说明问题:
    表结构相同,且两个表均用控件ADODC, 将ADODC1 的记录追加到ADODC2中,
    ADODC1  的记录已是取表中符合条件的范围。
    dim str as string
    str = "select * from tab1 where trim(str(pdate)) = '" & DTPicker1.Value & "' and team = '" & Combo2.Text & "'"
    Adodc1.RecordSource = str
    Adodc1.refresh
    Adodc2.RecordSource = "select * from tab2"
    Adodc2.refresh
    如何用语句实现? 
      

  4.   

    如果你不为了显示数据,又何必把数据调进客户端内存呢,只需要建一个数据库连接cn,然后执行
    cn.execute "insert into tab2 select * from tab1 where trim(str(pdate)) = '" & DTPicker1.Value & "' and team = '" & Combo2.Text & "'"
    注意:如果有自动增量字段,必须先加上set identity_insert tab2 off
      

  5.   

    不好意思,请问cacoda(cacoda) ,建数据库连接cn的语句如何写?
      

  6.   

    不要用两个记录集。
    如果不存在禁止重复记录问题的话,就照cacoda.
    不会用connection没关系。
    Adodc1.RecordSource = "insert into tab2 select * from tab1 where trim(str(pdate)) = '" & DTPicker1.Value & "' and team = '" & Combo2.Text & "'"
    Adodc1.Refresh
    同样有效。