简体   繁体   English

SSRS在一个报告中包含两个数据集

[英]SSRS two datasets in one report

I have a SSRS report with two datasets. 我有一个包含两个数据集的SSRS报告。 My report has one table with all fields from dataset 1. Is it possible to show the field from dataset 2 if the id field from dataset 1 = the id field from dataset 2? 我的报告有一张表,其中包含数据集1的所有字段。如果数据集1的id字段=数据集2的id字段,是否可以显示数据集2的字段?

I've tried using an expression on the field in the table to point to the field in dataset 2 but there is no link between the 2 datasets which I think I need. 我尝试在表中的字段上使用表达式来指向数据集2中的字段,但是我认为我需要的2个数据集之间没有链接。 are you able to do a select clause within the expression on the report? 您能够在报表的表达式中执行select子句吗?

any guidance would be appreciated 任何指导将不胜感激

I have tried the below as the expression but it doesn't work : 我已经尝试过下面的表达式,但是它不起作用:

=iif Sum(Fields!ID.Value, "DataSet2")=Sum(Fields!ID.Value, "DataSet3") then First(Fields!total.Value, "DataSet3")

Your question is very classic case of SSRS. 您的问题是SSRS的经典案例。

You have 2 ways to achieve this 您有两种方法可以实现这一目标

  1. SubReports (Which I personally like) 子报表(我个人比较喜欢)
  2. Lookup functions (which I sometimes find difficult dealing with) 查找功能(有时我发现很难处理)

Method1: Use subreport to display one report in another report 方法1:使用子报表在另一个报表中显示一个报表

  • .Create another report as the subreport and insert the child row data. 创建另一个报表作为子报表并插入子行数据。
  • Create a parameter named ID in the subreport. 在子报表中创建一个名为ID的参数。
  • In the main report, right-click to insert a subreport in the child row. 在主报表中,右键单击以在子行中插入一个子报表。
  • Right-click the subpeort to open the Subreport Properties, and select the subreport name in the drop-down list. 右键单击子报表以打开“子报表属性”,然后在下拉列表中选择子报表名称。
  • In the left panel of the Subreport Properties dialog box, click Parameters. 在“子报表属性”对话框的左面板中,单击“参数”。
  • Select Name in the drop-down list of ID, and select [ID] in the drop-down list of Value. 在ID的下拉列表中选择Name,然后在Value的下拉列表中选择[ID]。

Method2: Use lookupset function in SSRS 方法2:在SSRS中使用lookupset函数

In the Expression dialog box, modify the expression to look like this: 在“表达式”对话框中,将表达式修改为如下所示:

=join(Lookupset(Fields!ID.Value,Fields!ID.Value,Fields!Subject.Value,"DataSet2"),",")

The following screenshot is for your reference(The tablix is to use DataSet1): 以下屏幕快照仅供参考(tablix将使用DataSet1):

在此处输入图片说明

Refrences: Refrences:

  1. https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f30ff0d2-ba37-4bb8-b0a0-a6e06b3273fd/two-datasets-inside-a-same-tablix?forum=sqlreportingservices https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f30ff0d2-ba37-4bb8-b0a0-a6e06b3273fd/two-datasets-inside-a-same-tablix?forum=sqlreportingservices
  2. https://social.msdn.microsoft.com/Forums/sqlserver/en-US/2e6dfb5a-2de2-4d2f-96e5-4cb94543c6ec/asigning-two-data-sets-to-one-table-in-ssrs https://social.msdn.microsoft.com/Forums/sqlserver/en-US/2e6dfb5a-2de2-4d2f-96e5-4cb94543c6ec/asigning-two-data-sets-to-one-table-in-ssrs

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

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