简体   繁体   中英

How can I supply report parameters to ancillary reports from a “base” SSRS report?

I need to have several (four) reports that are identical except for the value of a particular parameter. I don't want the user to have to enter all parameters manually, though.

When they enter the following parameters:

BEATLES
-------
BegDate: 1962
EndDate: 1970
Unit: Beatles

I want four reports to run, using these parameters:

LENNON
------
BegDate: 1962
EndDate: 1970
Unit: John Lennon

MCCARTNEY
---------
BegDate: 1962
EndDate: 1970
Unit: Paul McCartney

HARRISON
--------
BegDate: 1962
EndDate: 1970
Unit: George Harrison

STARR
-----
BegDate: 1962
EndDate: 1970
Unit: Ringo Starr

So when the user enters the three parameters, the first two ("date") parameters and also the appropriate-for-the-ancillary-report "Unit" parameter ("John Lennon" to the first, "Paul McCartney" to the second, etc.) are passed.

The report "robot" says to itself after the person enters "Beatles" for Unit: "Oh, he entered 'Beatles'! So I'll pass 'John Lennon' as the Unit parameter to the first report, 'Paul McCartney' as the Unit parameter to the second report, " (etc.).

I tried doing this by supplying literal values inside practically-the-same Stored Procedures (as expounded on to some extent here , but it didn't work at all.

So I'm looking for some other way to put multiple related but distinct reports on the same surface. The ultimate goal is to see to it that, when ran and exported as Excel, each report (LENNON, MCCARTNEY, etc.) all display on their own sheet in the Excel file.

For now, though, I just need to know how to pass the appropriate parameters from one report ("BEATLES") to the others ("LENNON", etc.). I'm thinking of these as distinct reports all embedded in one report project/page, but perhaps they needed to be a report and then a bunch of subreports (if you're reading this, you probably know better than I do the inner workings and vagaries of SSRS).

So, how can I supply report parameters to ancillary (sub-?) reports from a "base" SSRS report - or is there another/better way to accomplish this?

I have a solution that may work for you.

Create a report with the 3 parameters you have mention above. Add to the report a dataset that will take the 3 parameters and return a dataset that is similar to this:

 Band Member Start End Page Beatles John Lennon 1962 1970 LENNON Beatles Paul McCartney 1962 1970 MCCARTNEY … 

In the report body add a List from the toolbox. Set the dataset name of the list to the name of the dataset above. In the Row Groups pain, there will be a row labelled (Details) for the List. Right-click on that row and choose Group Properties from the context menu. Add a new group and choose Page as the column to group on. Go to the Page Breaks section of the Group Properties dialog and check Between each instance of group . Add a sort if you like, then click the OK button.

Make sure the (Details) row in the Row Groups is selected, and then look for Group option in the Properties pain. Expand that, and look for the Page Name setting. Add an expression into the field like this (screen cap below, too):

=Fields!Page.Value

属性屏幕截图

This will make each page in the report have this value as the name. So, when you export this to Excel, each sheet will have its own name based on this value.

Add text boxes inside the List and set their values to the fields you need on each page. In this case Page , Start , End and Member . Add labels if you like to match what you have in your question.

As long as the dataset returns the 4 expected rows when you choose the right parameters, you should end up with a report that has 4 pages, one for each band member. When you export this to Excel, you will have 4 sheets and they should have the names from the Page field.

Hope this helps you!

Based on what is written here , this is how I accomplished this:

I added a Subreport and then dragged the existing report onto it. Then I selected the context menu item "Subreport Properties" and added a parameter ("Unit"), providing it with a "hard-coded/baked-in" value ("CHOPHOUSE") different from the one to be provided by the user for the main report.

Then, since I want to keep the same date values from the existing report, I added two more parameters to the subreport and set them to use the same values for the date range as those used there in the main report by selecting the "formula" ("fx") button and 2-clicking the appropriate parameter to be used as the passed-in (tramp) value:

在此处输入图片说明

That works.

I provided more detail at the answer to the similar question here .

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