select * into 表 from openrowset('SQLOLEDB' ,'sql服务器名';'用户名';'密码' ,数据库名.dbo.表名)
网上查到这条语句是全部复制,但如果事先存在该表就不能成功了。我要写个程序,每个月初把上个月产生的资料从库A的A表,复制到库B的B表中。
不知道直接用SQL语句能不能附加表中的部分内容到另一个已经存在表当中。请各位指教!

解决方案 »

  1.   

    insert into b (field1,field2,field3,field4,field5...) select field1,field2,field3,field4,field5...  from a where ...
      

  2.   

    楼上正解!
    Insert 表1(......)
    select ......
    from 表2
      

  3.   

    insert into table( 字段1,字段2....)
    select 字段1,字段2.... from openrowset('SQLOLEDB' ,'sql服务器名';'用户名';'密码' ,数据库名.dbo.表名)
      

  4.   

    insert into I_QC
    select * from openrowset('SQLOLEDB' ,'zixun;'sa';'' ,tex.dbo.I_QC) 
    where substring(fprojectNO,1,1)='D'服务器: 消息 213,级别 16,状态 4,行 1
    插入错误: 列名或所提供值的数目与表定义不匹配。必须指定源表跟目的表每个字段吗?
      

  5.   

    insert into I_QC
    select * from openrowset('SQLOLEDB' ,'zixun';'sa';'' ,tex.dbo.I_QC) 
    where substring(fprojectNO,1,1)='D'
      

  6.   

    OK了。谢谢!!
    刚才错误是因为两个数据表不一样。
    insert into openrowset('SQLOLEDB' ,'zixunA';'sa';'' ,tex.dbo.I_QC)
    select * from openrowset('SQLOLEDB' ,'zixunB';'sa';'',tex_T.dbo.I_QC) 
    where substring(fprojectNO,1,1)='D'