Sub Report là 1 kỹ thuật nhúng 1 report trong 1 report khác trong SSRS.
Tham khảo bài viết dưới đây, ta thấy việc xây dựng 1 Sub Report trong SSRS hoàn toàn đơn giản. Trong bài viết tác giả dùng 1 Report Parameter là DepartmentID, khi user điền giá trị cho DepartmentID, nó sẽ được truyền cho report cha và report được nhúng cho report cha.
Để có thể thực hành như bài viết, bạn cần download và cài đặt database AdventureWork cho SQL Server.
SubReport in SSRS
So far, we have placed report items within report items and data regions within data regions. Now in this article, we will put whole report inside another report. This is done using the sub report item. The sub report item is simply a placeholder in a report. Any report can be used as a sub report.
1. First of all open Visual Studio 2010 and open your SSRS project. Then add report named as DemoSubReport in your project.Now create Dataset. In dataset we used following query.
1
2
3
| SELECT DEPARTMENTID , NAME FROM HUMANRESOURCES.DEPARTMENT WHERE DEPARTMENTID = @DepartmentID |
@DepartmentID is our parameter.
2. Then right click on report area and goto Insert–>Table.
3. Now select data fields as a column in the table. After that your Report Design will look like below.
4. Similarly add another report named as SubReport. In that report we used following query:
1
2
3
4
5
6
| SELECT E.BUSINESSENTITYID,FIRSTNAME + ' ' + LASTNAME AS NAME FROM HUMANRESOURCES.EMPLOYEE E INNER JOIN PERSON.PERSON P ON E.BUSINESSENTITYID = P.BUSINESSENTITYID INNER JOIN HUMANRESOURCES.EMPLOYEEDEPARTMENTHISTORY EDH ON E.BUSINESSENTITYID = EDH.BUSINESSENTITYID WHERE EDH.DEPARTMENTID = @DepartnentID ORDER BY FIRSTNAME |
@DepartmentID is our parameter.
also add table as described in Step 2 & 3.
5. Now again goto our first report DemoSubReport. Then right click on report area and goto Insert –> SubReport.
6. Now your report design look like below:
7. Now right click on Sub Report Item and select Subreport Properties.
8. A Subreport Properties window pops up. In the Use this report as a subreport select SubReport which we generated earlier.
9. Then click on Parameters in left pane. Then Click on Add. A new row is added to the parameter grid.
In the Name text box, type the name of a parameter in the subreport. This name must match a report parameter in the subreport. If the subreport is in the same project, you can choose the parameter from the drop-down list.
Then click on OK button.
10. So we have done with Sub Report. To see the preview click on Preview tab. Give the value of DepartmentID and click on View Report Button.
Congratulations! We successfully completed SubReport in SSRS.
0 comments:
Post a Comment