Sunday 30 October 2011

Creating a SubReport in SSRS

A report within another report is a sub report. That is there will be two reports one the Master and the other the child where the master will invoke the child report. The child report or sub report can accept parameters from the master report and will execute its work. Moreover, it can be executed independently. Let us step into action.
Step 1:We will have two reports. The steps to be followed for both the reports are same only in the case of master report we will execute the below query
SELECT
             [PlayerID]
             ,[PlayerName]
             ,[BelongsTo]     
  FROM [SSRSExperiment].[dbo].[tbl_Players]
  
And for the Subreport we will execute the below query
SELECT 
      [PlayerName]      
      ,[MatchPlayed]
      ,[RunsMade]
      ,[WicketsTaken]
      ,[FeePerMatch]
  FROM [SSRSExperiment].[dbo].[tbl_Players]
WHERE  [BelongsTo]= @CountryName
Note that, we are passing the @CountryName parameter. So at runtime based on the parameter value passed , the sub report will be generated. Once the reports are created we will have two reports in our project as shown below
2.jpg
Testing the PlayerSubReport alone yields the below result
3.jpg
Step 2:Add a SubReport control in the main/master report.
4.jpg
Step 3:Right Click on the Subreport -> Subreport Properties
5.jpg
Step 4:From the General section of Subreport Properties window, select the subreport name (here it is PlayerSubReport) from the dropdown as shown below
6.jpg
And from the Parameters tab after clicking on the Add button, let us eneter the Parameter name as "CountryName"and the value as " =First(Fields!BelongsTo.Value, "DataSet1")". Once done , click on OK button
7.jpg
Step 5:That's it. Now let us run the report
8.jpg
So our Subreport has been generated.

No comments:

Post a Comment

SSIS: Creating Package Configurations

This post discusses the creation of Configuration Files and how they can be useful while migrating a package from one environment to an...