Today I am going to talk about(or rather write about) building Subrpeorts in SQL Server Reporting Services (SSRS).
First, let's create two simple reports -
1. EmployeeSummary report - Parent report.
2. EmployeeDetails report - Subreport.
NOTE: If you are well familiar with creating reports you can jump right to the Building Subreport section below.
Start Business Intelligence Development Studio, go to file menu, select new and then select Project. The New Projectdialog box appears, select the Report Server Project template and type a relevant name as shown below.
The first step in creating a report is to add a Data Source to connect to the database. Right-click Shared Data Sourcesand select Add New Data Source. Give a relevant name to the Data Source and click the edit button to define a new Connection as shown below. Click OK twice to create the new data source.
Right-click the Reports folder and go to Add menu and select New Item...
The Add New Item dialog box appears, select the Report template and type a proper name(in this case it is EmployeeSummary) for the report as shown below and click ok. This will be a Summary report that shows all the Employees and the number of hours they worked for a given month.
Now click on the Dataset drop down box and select New Dataset as shown below.
The Dataset dialog box appear, type a relevant name for the dataset and type a query to cater the report as shown below.
Now click on the Layout tab, drag Table from the Toolbox and drop it on to the body of the report as shown below.
GO to View menu and click Datasets to get the Datasets window if its not open already. Now drag and drop the required fields from the Dataset into the layout as shown below. Please be sure to drop the fields in the detail section. Also, do some basic formatting such as adjusting the column width, header color etc to make the report look pretty :)
Now click the Preview tab to look at the new report we just created. This will server as our main report or summary report. Now we will create a subreport which will server as a detail report. Please note that this is just sample data created for demo purpose.
Now let's create another report which will be our subreport. Right-click the Reports folder and go to Add menu and select New Item...
The Add New Item dialog box appears, select the Report template and type a proper name(in this case it is EmployeeDetails) for the report. This will be a detail report that shows all the Employees, the Practice Area they belong to, whether permanent employee or a contractor and utilization in percentage. Your screen should look similar to the one shown below.
Similar to how we did for the first report, we will need to create a new Dataset, type the query for the report data as shown below.
Again, as we did for the first report, click on the Layout tab, drag Table from the Toolbox and drop it on to the body of the report, drag and drop the required fields from the Dataset into the layout as shown below.
Click the prview tab to view the data as shown below.
Now let's create a parameter in the subreport on EmployeeNumber. In most of the cases, you will likely have a parameter on subreport and you will pass the parameter from the parent report to the subrpeort. To be more specific, when you place the subreport in the main report, you can select the report parameter and a value to pass from the parent report to the report parameter in the subreport.
Go back to the layout tab, go to Report menu and select Report Parameters as shown below.
The Report Parameters dialog box appears. Click Add and create a parameter as shown below.
Click on the Data tab and add a WHERE clause to the query as shown below. Please note the parameter we just created in the WHERE clause. Now let's get to the meet and potatoes of this post -
Building Subreport
In the main report(parent report), add a column where you want your subreport to be displayed. I will add it right after the EmployeeNumebr Column in this example.
From the Toolbox, drag Subreport and drop it onto the detail section of the new column we just created. Please see the screen shot below.
Righ-click on the cell where you dropped the Subreport, in the Subreport dropdown box, select EmployeeDetails as the subreport as shown below.
Now go to the Visibility tab and select the options as shown below. This will ensure that the subrpeort can be toggled using the EmployeeNumber column.
Go to Parameter tab and set the options below to pass the parameter from the main report to the subreport.
Save the report and click Preview to look at the final report as shown below.
Nice, thanks
ReplyDeletebetter than microsoft course material, thank you
ReplyDeleteGood one....
ReplyDeleteThanks ! ^_^
ReplyDeleteThanku so much I am stucking in this from last two days it gives me a greatful solution..:)
ReplyDeleteCan We Use Multiple SubReport in Single RDLC Report ....???? Because i Need To Use 10 Sub Report ....in One Master Report....
ReplyDeleteThis is a right and accurate example for creation of subreport
ReplyDeletethanks a lot...
may god bless u..
How Can we get the @EmployeeNum here
ReplyDeletegdggfggfgf
ReplyDeleteNetgear Nighthawk Router Solutions
ReplyDeletehttps://nighthawkrouterlogin.weebly.com/
https://www.vingle.net/posts/2732752
https://study.mdanderson.org/eportfolios/2424/Home/How_to_Check_Your_Nighthawk_Router_for_Malware
http://mywi-fiext.over-blog.com/2019/11/an-all-inclusive-guide-to-reset-netgear-nighthawk-ac1750-router.html
https://utah.instructure.com/eportfolios/30119/Home/Netgear_Nighthawk_X4_AC2350_R7500_Router_Setup_Guide
https://uberant.com/article/624737-is-the-nighthawk-ac1900-wifi-router-best-for-online-gaming/
https://www.selfgrowth.com/articles/cant-access-netgear-nighthawk-router-login-page-try-these-tips
http://netgearsol.mystrikingly.com/blog/can-t-log-in-to-netgear-router-here-s-the-solution
http://nighthawkmywifiext.mystrikingly.com/blog/fix-my-wifi-devices-can-t-detect-netgear-extender-network-name
Hey I’m Martin Reed,if you are ready to get a loan contact.Mr Benjamin via email: 247officedept@gmail.com ,WhatsApp:+1 989-394-3740 I’m giving credit to his Service .They grant me the sum 2,000,000.00 Euro. within 5 working days.Mr Benjamin work with group investors into pure loan and debt financing at the low ROI to pay off your bills or buy a home Or Increase your Business. please I advise everyone out there who are in need of loan and can be reliable, trusted and capable of repaying back at the due time of funds.
ReplyDeleteStaying aware of the patterns and overhauling one's innovative abilities is important to forestall becoming outdated. Each independent analyzer should be in fact capable in this present circumstance to acquire further understanding, find actual success, and satisfactorily report framework defects and disappointments to engineers. A QA testing expert who is capable in necessities examination, plan, and coding will have a more profound comprehension of the deformity life cycle. They can rapidly figure out what segment of code contains the most blunders and how those mistakes may be fixed by working with engineers>> freelance tester
ReplyDeleteAttract Group's web development services are truly outstanding, combining innovation and expertise to create unique and high-quality websites. Their team of skilled professionals is dedicated to delivering tailor-made solutions that meet the specific needs of each client. The attention to detail and commitment to excellence is evident in every project they undertake. With their extensive experience and cutting-edge techniques, Attract Group is a top choice for anyone seeking top-notch web development services.
ReplyDelete