问题描述
我有一个查询将返回任意数量的结果集,所有结果集都具有相同的列 - 即一个用于经理,然后每个员工说经理负责一个.
I have a query that will return an arbitrary number of result sets, all with the same columns - i.e. one for a Manager and then one each employee said Manager is responsible for.
在 Mgmt Studio 中运行 SQL 工作正常 - 我的主"和详细信息"表已成功呈现.但是,如果我只是在 SSRS 报告向导的数据集查询中输入相同的 SQL,则只会报告第一个结果集.
Running the SQL in Mgmt Studio works fine - my 'master' and 'details' tables are successfully rendered. However if I simply enter the same SQL in a dataset query in SSRS Report Wizard, only the first result set gets reported on.
如何在一份报告中将我的一个 Master + 所有 Details 结果集呈现为单独的表格?关键是查询将生成任意数量的结果集.
How can I get my one Master + all Details result sets rendered as separate tables in the one report? The key thing is that the query will generate an arbitrary number of result sets.
推荐答案
遗憾的是,来自 2008 文档:
...来自关系数据库的结果集,可以由运行数据库命令、存储过程或用户定义的函数产生.如果通过单个查询检索到多个结果集,则仅处理第一个结果集,而忽略所有其他结果集.
所以恐怕您只能选择更复杂的选项.我建议:
So I'm afraid you're limited to more convoluted options. I'd suggest either:
- 将所有结果集 UNION ALLed 返回到一个大的结果集中,并有一个额外的列来指示结果的每个部分针对哪个经理/员工,或者
- 创建一个主"报告和随附代码,为您报告的每个经理/员工显示一个子报告.子报表将使用存储过程的一个版本,一次为一个人呈现报表结果.
后者可能是更简洁的方法.
The latter will probably be the cleaner approach.
这篇关于返回多个结果集的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!