同一数据库复制表为
select * into ls1 from ls2
如果我想把数据库a的表ls1复制到b的数据库ls2(ls2本来不存在)还有一个小问题怎么用查询分析器中将表ls1中id中的编号去掉左边第一位

           id
          015
          078
          099
          135
我想得到
           id
          15
          78
          99
          35

解决方案 »

  1.   

    select * into b..ls2 from a..ls1
      

  2.   

    --> 测试数据: #T1
    if object_id('tempdb.dbo.#T1') is not null drop table #T1
    create table #T1 (id varchar(11))
    insert into #T1
    select '015' union all
    select '078' union all
    select '099' union all
    select '135'select id from #T1select id=right(id,len(id)-1) into #T2 from #T1select * from #T2/*
    id
    -----------
    15
    78
    99
    35
    */
      

  3.   

    还有一个小问题怎么用查询分析器中将表ls1中id中的编号去掉左边第一位 
    select stuff(id,1,1,'') as id from ls1
      

  4.   

    select right(id,2) into b..ls1 from ls2
      

  5.   

    select right(id,2) into b..ls1 from ls2 我没说清楚,不一定是三位数 结贴了
      

  6.   

    ? 如果我想把数据库a的表ls1复制到b的数据库ls2(ls2本来不存在)select * into dbName2.dbo.ls2 from dbName1.dbo.ls1? 还有一个小问题怎么用查询分析器中将表ls1中id中的编号去掉左边第一位 
    select substring(id,2,len(id)-1) from ls1