简体   繁体   English

在单行SSRS表达式中组合多个行值

[英]Combining Multiple row values in a single line SSRS expression

There are three rows in my SQL output which I would like to view them in a single line when I want to view them while running the SSRS report. 我的SQL输出中有三行,当我想在运行SSRS报表时查看它们时,我想在一行中查看它们。

Source Data 源数据

在此处输入图片说明

These two columns are part of my DataSet1 in the SSRS report. 这两列是SSRS报告中我的DataSet1的一部分。

Output I am expecting in the SSRS report (Expression): Semester 1 2017, Semester 2 2017, Semester 3 2017 我在SSRS报告中期望的输出(表达): 2017年第一学期,2017年第二学期,2017年第三学期

Can someone please help? 有人可以帮忙吗?

Check this https://docs.microsoft.com/en-us/sql/t-sql/functions/stuff-transact-sql 检查此https://docs.microsoft.com/zh-cn/sql/t-sql/functions/stuff-transact-sql

SELECT STUFF(
             (SELECT ',' + Semesters 
              FROM table t1
              FOR XML PATH (''))
             , 1, 1, '') AS Semesters from table t2

Yes you could use STUFF() function with xml path method for that 是的,您可以将STUFF()函数与xml path方法一起使用

SELECT DISTINCT
       Semester = STUFF(
                       (
                           SELECT ','+CONCAT(Semester, ' ', [year])
                           FROM <table> FOR XML PATH('')
                       ), 1, 1, '')
FROM <table>;

Update : You could use CONCAT() function for combining the year & Semester 更新:您可以使用CONCAT()函数合并yearSemester

Result : 结果:

Semester
Semester 1 2017,Semester 2 2017,Semester 3 2017

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM