简体   繁体   中英

SSRS loop for report and subreport

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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