本帖最后由 zmcici 于 2010-07-21 14:54:32 编辑

解决方案 »

  1.   

    这是典型的合并列值问题
    下面给出测试sql语句 
    create table test([a] nvarchar(20),b varchar(2))
    insert test
    select '张三','1' 
    union all
    select '李四','2' 
    union all
    select '张三','3' 
    go--select * from test
    select * from
    (
    select distinct a from test
    ) m
    outer apply( select [b] = stuff(replace(replace(
    (
    select b from test n
    where a = m.a
    for xml auto
    ),'<n b="', '/'), '"/>', ''), 1, 1, '')
    )n
    ---------------------------------------------
    a       b
    李四 2
    张三 1/3
    详情请参考
      

  2.   

    select a,[values]=
    stuff(replace(replace((select [b] from tb where a=t.a for xml AUTO), '"/><tb b="','/'), '"/>',''),1,9,'')
    from tb t
    group by a
      

  3.   

    SELECT  a,
            STUFF(( SELECT  '/' + CAST(b AS VARCHAR(10))
                    FROM    表
                    WHERE   a = T2.a
                  FOR
                    XML PATH('')
                  ), 1, 1, '') AS b
    FROM    表 AS T2
    GROUP BY a
      

  4.   

    拼接字符串
    http://topic.csdn.net/u/20100412/22/fec647ea-73d0-480b-92e9-8af61ef3c978.html