select ,(select num from table1 b where b.id=1)as num1,(select b.num from table1 b where b.id=2) as num2 from table1 
未测试过不知行不行

解决方案 »

  1.   

    selct a.*,b.* from tt a left join tt b on cast(a.id as decimal(5,0))+1=cast(b.id as decimal(5,0))
      

  2.   

    create table A
    (
        id varchar(10),
        num varchar(100)
    )
    insert A 
    select '01','01,02,03,04' union
    select '02','05,06,07,08' DECLARE @T_SQL varchar(8000)
    set @T_SQL=''
    select  @T_SQL=@T_SQL + '(select num from A where id=''' + id + ''')' + ' + '','' + ' from A
    set @T_SQL='select ' + left(@T_SQL,len(@T_SQL)-len(' + '','' + '))
    exec (@T_SQL)
      

  3.   

    declare @Sum_num varchar(8000)
    set @Sum_num=''
    select @Sum_num=@Sum_num+num from table1 where ......
    select @Sum_num
      

  4.   

    declare @Sum_num varchar(8000)
    set @Sum_num=''
    select @Sum_num=@Sum_num+num+',' from table1 where ......
    set @Sum_num=left(@Sum_num,len(@Sum_num)-1)
    select @Sum_num
      

  5.   

    declare @t table(id varchar(2), num varchar(50))
    insert @t
    select '01','01,02,03,04' union all
    select '02', '05,06,07,08'
    select newnum=(select num from @t where id='01')+','+(select num from @t where id='02')/*
    newnum                                                                                                
    -----------------------
    01,02,03,04,05,06,07,08
    */
      

  6.   

    To mislrb(aben):
    你那是啥玩意儿?不具有通用性啊^_^
    难道有100行你就有100个()加起来?
      

  7.   

    CREATE TABLE table1
     (
      id varchar(10),
      num varchar(100)
     ) INSERT table1 SELECT '01','01,02,03,04'
     UNION SELECT '02','05,06,07,08,09' DECLARE @num_Sum VARCHAR(8000)
     set @num_Sum=''
     SELECT @num_Sum=@num_Sum + a.num+',' FROM table1 a SELECT left(@num_Sum,len(@num_Sum)-1)
     
     DROP TABLE table1