SSRS - Group_Concat等效使用表达式?

Gre*_*reg 2 sql t-sql sql-server ssrs-2008

我可以在Sql Server Reporting服务中使用表达式来组合组中列的所有值吗?我正在尝试完成MySQL的group_concat函数所做的事情,但是在报告中(不在查询中).

例.我想制作这些数据:

Group 1  Value
Test
         A
         B
Test 2
         C
         D
Run Code Online (Sandbox Code Playgroud)

在报告中看这个:

Group 1 Value
test    A, B
test 2  C, D
Run Code Online (Sandbox Code Playgroud)

KM.*_*KM. 5

尝试这样的东西(适用于SQL Server 2005及以上版本):

set nocount on;
declare @t table (id int, name varchar(20), x char(1))
insert into @t (id, name, x)
select 1,'test1', 'a' union
select 1,'test1', 'b' union
select 1,'test1', 'c' union
select 2,'test2', 'a' union
select 2,'test2', 'c' union
select 3,'test3', 'b' union
select 3,'test3', 'c' 
SET NOCOUNT OFF

SELECT p1.id, p1.name,
          stuff(
                   (SELECT
                        ', ' + x
                        FROM @t p2
                        WHERE p2.id=p1.id
                        ORDER BY name, x
                        FOR XML PATH('') 
                   )
                   ,1,2, ''
               ) AS p3
      FROM @t p1
     GROUP BY 
        id, name
Run Code Online (Sandbox Code Playgroud)

OUTPUT:

id          name                 p3
----------- -------------------- ---------
1           test1                a, b, c
2           test2                a, c
3           test3                b, c

(3 row(s) affected)
Run Code Online (Sandbox Code Playgroud)