表A有id,time,name,address
表B有id,time,name
想把A里面 2010-10-10<time<2010-10-20的数据
都插到b里,一次性
谢谢

解决方案 »

  1.   


    insert into @b(id,time,name)
    select id,time,name from @a
    where time between '2010-10-10' and '2010-10-20'
      

  2.   


    insert into 表B(id,time,name)
    select id,time,name from 表A
    where time between '2010-10-10' and '2010-10-20'上面把表打错了
      

  3.   

    insert into 表B(id,time,name)
    select id,time,name from 表A
    where time between '2010-10-10' and '2010-10-20'
      

  4.   

    insert into tb2
    select * from tb1 where id>5id          data2
    ----------- -----------
    2           1
    3           5
    4           4
    6           10
    7           10
    8           10
    9           10
    10          10
    11          17(9 row(s) affected)
      

  5.   


    insert into 表B(id,time,name)
    select id,time,name 
    from 表A
    where '2010-10-10'<time and time<'2010-10-20'-- between '2010-10-10' and '2010-10-20' 相当于'2010-10-10'<=time and time<='2010-10-20'
      

  6.   

    发现可能存在的两个问题,完全解决问题:假设1 
    --time字段是字符型
    insert into 表B(id,[time],name)
    select id,[time],name from 表A
    where convert(varchar(10),[time],120) between '2010-10-10' and '2010-10-20'
    假设2
    --期间内有500万条记录,基本是不太可能。用如下方式:
    --CMD下导出
    D:\>bcp "select id,time,name from 表A where time between '2010-10-10' and '2010-10-20'" queryout inserto.dat -T -c--SQL执行导入
    BULK INSERT 数据库名.架构名.表B FROM 'D:\inserto.dat'
      

  7.   

    如果符合假设2 的部分。
    bcp的where内容调整为假设1的where内容。(忘了修改日期转换)
      

  8.   

    A,B表中的id,是自动编号。还是怎么。---B表中的id不是自动编号insert into B(id,[time],name)
    select id,[time],name from A
    where convert(varchar(10),[time],120) between '2010-10-10' and '2010-10-20'---B表中的id是自动编号insert into B([time],name)
    select [time],name from A
    where convert(varchar(10),[time],120) between '2010-10-10' and '2010-10-20'
      

  9.   

    insert into b (id,time,name) select id,time,name where time between '2010-10-10' and '2010-10-20'
      

  10.   


    insert into B
    select id,time,name from A
    where time between '2010-10-10' and '2010-10-20'