在主报告中访问子报告值 - SSRS

时间:2016-04-04 05:56:18

标签: reporting-services ssrs-2008 ssrs-2008-r2 ssrs-2012 ssrs-2014

我在子报告

中有主要报告

使用报告服务,如何从Sub报告中获取主报告中的值?

我根据主报告的tablix数据调用子报告。例如,我在主报表上有tablix,它将@Number值传递给子报表以获取一些子记录,我希望总值的总和回到主报表。我怎样才能做到这一点!

我尝试制作一个无法帮助我的数据集。每次都获得0计数。

我通过在主报表上创建子报表数据集在主报表上使用了以下表达式。

awk

然而,我没有找到任何有效的报告,请帮助。

1 个答案:

答案 0 :(得分:3)

How to do it by referencing the subreport directly

Supposedly, you can access subreport items in the following way:

[Reports]![YourReportName]![YourSubReportName]![TheValueFromTheSubReportYouWantToReference]

I've seen references to this sort of thing in the past, but I've never been able to get reportItems references (or this sort of thing) to work consistently and in the way I imagined it would.

Keeping in mind of course that you're referring to a subreport that is presumably repeating multiple times, which instance of the given subreport would you be pulling with the reference above? I think you'll find this more trouble than it's worth.

How I recommend you approach it

As I've stated above, I think referencing the subreport directly is likely to be difficult and unreliable if not impossible. Instead, you're stating that you're passing @Number into your subreport. If you're utilizing a view or function within your subreport to pull the data based on @Number, then you could easily embed the same logic plus an aggregate function in your main report. This way, you can reference an aggregate value from a query in your main report that is utilizing the same calculations and data as your subreport.

If your subreport is not using views, functions, or shared datasets and you cannot (or choose not to use) views, functions, or shared datasets (notice I listed them twice for emphasis), then you'd be stuck reproducing your SQL query in the main report and calling the query logic and aggregating it in the main report. This is potentially a maintenance nightmare (and one I'm actively trying to minimize in my own organization) as you must maintain the same SQL logic in two places. That said, it can be done and done fairly easily depending on the complexity of your SQL query in the subreport.

If you have questions, leave them as a comment and I'll do my best to help.