Hour 7. Sub Reports
Introduction
First, we create the first report with a country list then create another one for the state list based on the parameter passed, in other words, country row id and then display the state report as a sub-report.
Sub Report in SSRS
Step 1
To add the report, right-click on "Reports", select "Add" and click on "New Item".
![New Item](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/New%20Item.jpg)
Step 2
Select "Report" and provide the report name.
![Report](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/Report.jpg)
Step 3
Add a data source to the report data, right-click on "Data Sources" and click on "Add Data Source".
![Data Sources](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/Data%20Sources.jpg)
Step 4
Provide a data source name and select shared data source reference.
![source reference](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/source%20reference.jpg)
Step 5
Add a dataset in the report data, right-click on "Datasets" and click on "Add Dataset".
![Add Dataset](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/Add%20Dataset.jpg)
Step 6
Provide a dataset name and select shared dataset.
![select shared dataset](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/select%20shared%20dataset.jpg)
Step 7
Right-click on the design surface, select "Insert" and click on "Table".
![Table](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/Table.jpg)
Step 8
Set "Country Row ID" as the column header and map the "CountryRowID" field for that column.
![CountryRowID](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/CountryRowID.jpg)
Step 9
Set "Country Name" as the column header and map the "CountryName" field for that column.
![Country Name](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/Country%20Name.jpg)
Step 10
Select and delete the third column.
![column](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/column.jpg)
Step 11
Now the design of the main report is ready with the columns "Country Row ID" and "Country Name".
![main report](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/main%20report.jpg)
Step 12
To check the report click on the "Preview" tab and we will have a country list.
![review](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/review.jpg)
Step 13
- Now let's create a state report with the parameter CountryRowID.
- To add a report, right-click on "Reports", select "Add" and click on "New Item".
Step 14
Select "Report" and provide the report a name.
![provide report](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/provide%20report.jpg)
Step 15
To add a parameter, right-click on "Parameters" in Report Data and click on "Add Parameter".
![Add Parameter](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/Add%20Parameter.jpg)
Step 16
Provide a parameter name and select its visibility as visible.
![visible](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/visible.jpg)
Step 17
- Add a data source in report data.
- Right-click on "Data Sources" and click on "Add Data Source".
Step 18
Provide the data source a name and select data source reference.
![select data source reference](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/select%20data%20source%20reference.jpg)
Step 19
- Add a data set in the report data.
- Right-click on "Datasets" and click on "Add Dataset".
Step 20
Provide a data set name and select shared data set.
![select shared data set](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/select%20shared%20data%20set.jpg)
Step 21
- Open the report file.
- Right-click on the design surface, select "Insert" and click on "Table".
Step 22
- It will add a table on the report design surface.
- Set "State Row ID" and "State Name" in two separate column headers.
- Map "StateRowID" in the first column.
Step 23
Map "StateName" in the second column.
![second column](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/second%20column.jpg)
Step 24
Select and delete the third column.
![delete the column](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/delete%20the%20column.jpg)
Step 25
Now the report design is ready.
![Now report design](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/Now%20report%20design.jpg)
Step 26
- Click on preview to check the report.
- Pass some parameter value.
Step 27
You can see the list of states for the country you passed in the parameter.
![states for the country](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/states%20for%20the%20country.jpg)
Step 28
- Add one more parameter in Report Data.
- Right-click on "Parameters" and click on "Add Parameter".
Step 29
Select "General", provide a parameter name and select its visibility to "Hidden".
![Specify values](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/Specify%20values.jpg)
Step 30
- Select "Default Values".
- Select the "Specify values" option and specify "0" as the value.
Step 31
Open "CountryMasterReport.rdl", right-click on "CountryRowID" and click on "Text Box Properties".
![Map the parameter](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/Map%20the%20parametert.jpg)
Step 32
- In the text box properties select "Action".
- Select "Go to report" in Enable as an action.
- Specify "CountryMasterReport".
- Map the parameter with "CountryRowID".
Step 33
Right-click on the report design surface, select "Insert" and click on "Subreport".
![Subreport](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/Subreport.jpg)
Step 34
Right-click on the subreport area and select "Subreport Properties".
![Subreport Properties](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/Subreport%20Properties.jpg)
Step 35
Select "General", provide the appropriate name.
Select the report that we want to display as a subreport, in other words "RptCountryDetailReport".
![RptCountryDetailReport](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/RptCountryDetailReport.jpg)
Step 36
Select "Parameters" and map the parameter for CountryRowID.
![map the parameter for CountryRowID](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/map%20the%20parameter%20for%20CountryRowID.jpg)
Step 37
Now our complete report design is ready.
![design is ready](https://www.csharp.com/admin/step-by-step-ssrs-in-11-hours-hour-701092019123732/Images/design%20is%20ready.jpg)
Step 38
- Click on the "Preview" tab and you can see the country list.
- Now click on any of the country row ids and the state list is shown as a sub report.
Author
Akshay Patel
58
28.6k
7.7m