自己UP.
各位在CSDN中看到相關問題的解決貼子,請貼出來其鏈接.謝了!

解决方案 »

  1.   

    --建表
    create table ta(elno varchar(1),elrmk varchar(100))
    insert into ta
    select  'A','C1'
    union all select 'A','C2,C3'
    union all select 'B','C1'
    union all select 'A',' R1'
    union all select 'B','D1,D2,D3'
    union all select 'A','D4'
    union all select 'C','C1,C2'
    select * from ta--建臨時表
    create table temtab (id int identity(1,1),elno varchar(1),elrmk varchar(1000))
    insert into temtab(elno) select distinct elno from ta
    select * from temtabdeclare @s varchar(1000)
    declare @maxid int,@intI int
    select @maxid=max(id) from temtab
    set @intI=1
    while @intI<=@maxid
    begin
    set @s=''
    select @s=@s+elrmk+',' from ta  where elno in (select elno from temtab where id=@intI)
    update temtab set elrmk=@s where id=@intI
    set @intI=@intI+1
    end
    --刪除表
    drop table ta
    drop table temtab--測試結果
    select elno,elrmk from temtabelno      elrmk
    =======================================
    A C1,C2,C3, R1,D4,
    B C1,D1,D2,D3,
    C C1,C2,
      

  2.   

    TO: hdhai9451,謝謝!
    順便問一下,你寫的SQL語句是通過什麽輔助軟件寫的,怎麽這麽快?
      

  3.   

    http://community.csdn.net/Expert/topic/3295/3295858.xml?temp=.1170313