SSRS 2005:将列显示从项目列值/一行更改为其他内容?
我有一个像这样的表/数据集:
1/1/2009 | Training 1 | Mike
1/1/2009 | Training 1 | Bill
1/1/2009 | Training 1 | Steve
我想显示为
1/1/2009 | Training 1
Mike, Bill, Steve
这个想法是,通过在页面的大部分向下打印一列,但将空间缩短为水平列表或内部的分栏结果,不会浪费最终的打印页面空间那个领域。 什么是最好的方法?
我想通过报表设计器来处理这个问题,而不是用 SQL 结果来处理。 我看到了几种接近但不准确的方法。 我在 SSRS 2005。
I have a table/dataset like:
1/1/2009 | Training 1 | Mike
1/1/2009 | Training 1 | Bill
1/1/2009 | Training 1 | Steve
I would like to display as
1/1/2009 | Training 1
Mike, Bill, Steve
The idea is that the resulting printed page space is not wasted by printing one column on most of the page down but shortening the space to either a horizontal list or a columned result inside that field. What is the best way?
I would like to handle this is report designer as opposed to mucking with SQL results. I see several ways that gets close but not exact. I'm on SSRS 2005.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不使用 SQL 生成 CSV,然后尝试使用矩阵控件将日期/训练上的行更改为列和组...但中间不会有逗号。
Without using SQL to generate the CSV, then try a matrix control to change the rows into columns and groups on the date/training... but you won't have commas in between.
任意标记您的三列
Date
、Session
和Participant
以及您的表格MyTable
)(我 不要认为您能够仅在报表设计器中执行此操作。 我认为最好的方法是编写一个标量值函数,它接受一个
datetime
和一个varchar
(或两个varchar
)作为两个输入并生成varchar
输出。 该函数看起来像这样:然后,当您从
MyTable
中选择时,使用(I'm arbitrarily labeling your three columns
Date
,Session
, andParticipant
, and your tableMyTable
)I don't think you're going to be able to do this solely in the report designer. The best way I see to do it is to write a scalar-valued function which takes a
datetime
and avarchar
(or twovarchar
s) as two inputs and produces avarchar
output. The function would look something like this:Then, when you select from
MyTable
, do it with我编写了以下查询来使用公用表表达式构建基本数据集,然后使用分组/串联操作来获取我认为您正在寻找的结果:
这会输出以下内容:
您可以在 SSRS 中根据需要格式化这些结果。 由于 DISTINCT 子句,无法保证这会在非常大的数据集上快速运行,但是您在大型数据集上执行的任何分组操作无论如何都会很慢。 在连接方面,使用像这样的 FOR XML 子句绝对是规则。
希望这可以帮助。
I wrote the following query to build a basic data set using a common table expression and then a grouping/concatenation operation to get the results I think you're looking for:
This outputs the following:
You can format these results however you want in SSRS. No promises that this will run fast on a very large dataset due to the DISTINCT clause, but any grouping operation you do on a large dataset would be slow anyway. Using the FOR XML clause like this absolutely rules when it comes to concatenation.
Hope this helps.
在 SSRS 中进行聚合串联的常用方法是使用自定义代码。 请参阅此处的示例:
http://blogs。 msdn.com/suryaj/archive/2007/08/11/string-aggregation.aspx
以下是基本形式的自定义代码:
接下来是您要显示的分组级别:
The usual way to do aggregate concatenation in SSRS is with custom code. See here for an example:
http://blogs.msdn.com/suryaj/archive/2007/08/11/string-aggregation.aspx
Here's the custom code in basic form:
Followed by this at the grouping level you want to display:
我最终在 t-sql 的 select 部分中使用了 SQL stuff/xml 语句,并连接回整个 select 的数据。 像这样的东西: http://www.kodyaz.com/articles/连接使用-xml-path.aspx
I wound up using a SQL stuff/xml statement in the select portion of the t-sql with a join back to the overall select's data. Something like this: http://www.kodyaz.com/articles/concatenate-using-xml-path.aspx