user bookid
陈晓婷 I247.5
张嘉伟 TM5
张嘉伟 TM5
施静 I247.5
施静 B84
祝欣 I247.5
祝欣 K92
施静 I11
吴盈 I247.5
卢婉秋 I247.5
包玉丽 K82
包玉丽 I247.5
钱文予 Q93
钱文予 Q93
朱希强 TS21
朱希强 TS21
张苏静 I247.5请问下,假如是以上的这个表格,只保留以T开头的bookid,并且插入到新德表格中,那sql语句应该怎么写?

解决方案 »

  1.   

    select * into newtable from tb where left(bookid,1)='T'
      

  2.   

    or:
    select * into newtable from tb where bookid like 'T%'
      

  3.   


    select * into newtb from tb where left(bookid,1)='T'
      

  4.   

    INSERT INTO NEWTBNAME (user,bookid)
    SELECT user,bookid
    FROM OLDTBNAME
    WHERE LEFT(ISNULL(bookid,'UNT'),1) = 'T'
      

  5.   

    INSERT 新德表格(USER,BOOKID)
    SELECT USER,BOOKID
    WHERE BOOKID LIKE 'T%'
      

  6.   

    select into  T2
     user, bookid  from T1  where bookid like 'T%'
      

  7.   

    INSERT 新德表格(USER,BOOKID)
    SELECT USER,BOOKID
    FROM 这个表格
    WHERE BOOKID LIKE 'T%'
      

  8.   

    怎么会!create table tb([user] nvarchar(10),bookid varchar(10))
    insert into tb select '陈晓婷','I247.5'
    insert into tb select '张嘉伟','TM5'
    insert into tb select '张嘉伟','TM5'
    insert into tb select '施静','I247.5'
    insert into tb select '施静','B84'
    insert into tb select '祝欣','I247.5'
    insert into tb select '祝欣','K92'
    insert into tb select '施静','I11'
    insert into tb select '吴盈','I247.5'
    insert into tb select '卢婉秋','I247.5'
    insert into tb select '包玉丽','K82'
    insert into tb select '包玉丽','I247.5'
    insert into tb select '钱文予','Q93'
    insert into tb select '钱文予','Q93'
    insert into tb select '朱希强','TS21'
    insert into tb select '朱希强','TS21'
    insert into tb select '张苏静','I247.5'
    go
    select * into newtable from tb where left(bookid,1)='T'
    select * from newtable 
    /*
    user       bookid
    ---------- ----------
    张嘉伟        TM5
    张嘉伟        TM5
    朱希强        TS21
    朱希强        TS21(4 行受影响)*/
    go
    drop table tb,newtable
      

  9.   

    create table tb([user] nvarchar(10),bookid varchar(10))
    insert into tb select '陈晓婷','I247.5'
    insert into tb select '张嘉伟','TM5'
    insert into tb select '张嘉伟','TM5'
    insert into tb select '施静','I247.5'
    insert into tb select '施静','B84'
    insert into tb select '祝欣','I247.5'
    insert into tb select '祝欣','K92'
    insert into tb select '施静','I11'
    insert into tb select '吴盈','I247.5'
    insert into tb select '卢婉秋','I247.5'
    insert into tb select '包玉丽','K82'
    insert into tb select '包玉丽','I247.5'
    insert into tb select '钱文予','Q93'
    insert into tb select '钱文予','Q93'
    insert into tb select '朱希强','TS21'
    insert into tb select '朱希强','TS21'
    insert into tb select '张苏静','I247.5'
    go
    select * into 新的表格 from tb where bookid like 'T%'
    select * from 新的表格 
    /*
    user       bookid
    ---------- ----------
    张嘉伟        TM5
    张嘉伟        TM5
    朱希强        TS21
    朱希强        TS21(4 行受影响)*/
    go
    drop table tb,新的表格
      

  10.   

    use tempdb
    go
    select user, bookid
    into #t
    from tb
    where tb.bookid like 'T%'Select * from #t  --查看插入的表
    drop table #t
    go
      

  11.   

    create table tb([user] nvarchar(10),bookid varchar(10))
    insert into tb select '陈晓婷','I247.5'
    insert into tb select '张嘉伟','TM5'
    insert into tb select '张嘉伟','TM5'
    insert into tb select '施静','I247.5'
    insert into tb select '施静','B84'
    insert into tb select '祝欣','I247.5'
    insert into tb select '祝欣','K92'
    insert into tb select '施静','I11'
    insert into tb select '吴盈','I247.5'
    insert into tb select '卢婉秋','I247.5'
    insert into tb select '包玉丽','K82'
    insert into tb select '包玉丽','I247.5'
    insert into tb select '钱文予','Q93'
    insert into tb select '钱文予','Q93'
    insert into tb select '朱希强','TS21'
    insert into tb select '朱希强','TS21'
    insert into tb select '张苏静','I247.5'
    go
    --如果新表已经存在:
    create table 新的表格([user] nvarchar(10),bookid varchar(10))
    go
    insert into 新的表格 select * from tb where bookid like 'T%'
    select * from 新的表格 
    /*
    user       bookid
    ---------- ----------
    张嘉伟        TM5
    张嘉伟        TM5
    朱希强        TS21
    朱希强        TS21(4 行受影响)*/
    go
    drop table tb,新的表格
      

  12.   

    ---方法还是很多的
    select * into newtb from tb 
    where left(bookid,1)='T'
    select * into newtb from tb
    where booid like 'T%'