带逗号的 SUM 字符串(SQL Server Reporting Services)

SUM string with comma (SQL Server Reporting Services)

我想获取字符串总和检查 "column 1"。

你知道怎么做吗?

jack, john, bill, joe, sindy

类似于

=JOIN(Fields!Column1.Value, ",")

样本TABLE

CREATE TABLE #TEMP(COLUMN1 VARCHAR(100),COLUMN2 VARCHAR(100))

INSERT INTO #TEMP
SELECT 'jack',1  
UNION ALL
SELECT 'john',1 
UNION ALL
SELECT 'bill',1
UNION ALL
SELECT 'joe',1
UNION ALL
SELECT 'sindy',1

查询

如果需要comma separate valuescount的值,可以避免在UNION ALL之前查询,只在UNION ALL之后执行查询。

SELECT NULL,COLUMN1,COLUMN2
FROM #TEMP

UNION ALL

SELECT DISTINCT 'TOTAL',
-- Here we convert to comma separated values
SUBSTRING(
            (SELECT  ', ' + COLUMN1
            FROM #TEMP T2 
            --WHERE C2.Id=Id AND C2.COLUM=COLUM            
            FOR XML PATH('')),2,200000) COLUMN1,
COUNT(COLUMN1) COLUMN2
FROM #TEMP T1