SSRS loop for report and subreport

2019-09-12 22:32发布

So I have a report with a matching subreport, based on two joined tables. The value: NameID from the one table is the parameter I wish to filter on.

The main table draws data from a query like this:

SELECT * 
FROM NameTable
Where NameID = '111'

The subreport then is made up of a join query using the NameID from the first table.

SELECT *
FROM OtherTable
WHERE OtherID IN 
(SELECT a.otherID 
FROM OtherTable a 
INNER JOIN NameTable b 
ON a.variable = b.variable 
WHERE b.NameID = '111')

I just want a way to make a matching report and subreport for every different NameID in the table. Is there a way to set a parameter or variable that can be then passed to the subreport or any other way for me to do this?

1条回答
可以哭但决不认输i
2楼-- · 2019-09-12 23:22

In your subreport create a parameter called NameID and use this in your SQL:

SELECT *
FROM OtherTable
WHERE NameID = @NameID

Add this subreport to your table in the main report. Click on the subreport properties and click the Parameters button. This shows the parameters of the linked report and allows you to put expressions of what values you want to pass. To pass the field to the subreport's parameter value, put in something like:

=Fields!NameID.Value
查看更多
登录 后发表回答