Reporting services ssrs中如何使用逗号分隔在单行中获取多行数据

Reporting services ssrs中如何使用逗号分隔在单行中获取多行数据,reporting-services,ssrs-2008,Reporting Services,Ssrs 2008,我必须在SSRS报告中创建一个报告。现在,我正在从SP获取以下数据: Col1 Col2 A123 cust1 A123 cust2 A123 cust3 A123 cust1, cust2, cust3 我的要求是显示以下结果: Col1 Col2 A123 cust1 A123 cust2 A123 cust3 A123 cust1, cust2, cust3 有人能告诉我怎么做吗?我能想到的唯一方法是在查询中处理它,并将它作为逗号分隔的列表带到报告中 CREATE TABLE #t

我必须在SSRS报告中创建一个报告。现在,我正在从SP获取以下数据:

Col1 Col2
A123 cust1
A123 cust2
A123 cust3
A123 cust1, cust2, cust3
我的要求是显示以下结果:

Col1 Col2
A123 cust1
A123 cust2
A123 cust3
A123 cust1, cust2, cust3

有人能告诉我怎么做吗?

我能想到的唯一方法是在查询中处理它,并将它作为逗号分隔的列表带到报告中

CREATE TABLE #temp(col1 VARCHAR(10), col2 VARCHAR(10))
INSERT INTO #temp VALUES 
    ('A123', 'cust1'),
    ('A123', 'cust2'),
    ('A123', 'cust3'),
    ('A125', 'cust1'),
    ('A125', 'cust2'),
    ('A125', 'cust3')

SELECT DISTINCT
    ot.col1,
    STUFF(
        (SELECT ', ' + CAST(it.col1 AS VARCHAR(10))
        FROM #temp it
        WHERE it.col1 = ot.col1
        FOR XML PATH('')), 1, 2, '') as List
FROM
    #temp ot

DROP TABLE #temp

您应该能够使用矩阵来实现这一点。看看这个问题。看看