The subreport will display the SalesOrderDetails records for
a given SalesOrderID. Again, this is for demonstration purposes only but you
can apply the same concept to your reports when you have data in two different
databases. You can also apply the same concept if you have two separate
queries that need to execute to produce data on a report.
Right click on the white space in the Details section and select InsertàSubreport… from the pop-up menu.
A square box will follow your mouse pointer until you left click in a
section. Left click in the Details section so the report is placed in the
Details section. The Insert Subreport dialog will appear.
Select the "Create a subreport with the Report Wizard option and
enter "SalesOrderDetail" for the New report name. Click the Report
This will display the Standard Report Wizard dialog box. The first step
in the wizard is to choose a data source for the subreport. Double click on
the Make New Connection to create a new connection to the AdventureWorks
Select SQL Native Client from the Provider list and click the Next
Enter the server name, a user name and password, and select the
AdventureWorks database from the database drop down list.
Click the Next button and then the Finish button.
Expand the AdventureWorks database to display the list of schemas.
Expand the Sales schema and the tables underneath it.
Select the SalesOrderDetail table and click the > button to move the
table to the Selected Tables list.
the Production schema and the tables underneath it.
the Product table and click the > button to move the table to the Selected
Tables list. The SalesOrderDetail has a foreign key to the Product table. The
report will display the product name and number for each record in the
SalesOrderDetail table rather than the foreign key.
the Next button.
Reports tries to determine the relationships between tables automatically and
usually does a good job. However, in this case it created two links where we only
want one between the Product.ProductID and SalesOrderDetail.ProductID. The link
between the rowguid fields between the two tables should be deleted. To do
this left click on the line between the two fields and press the Delete key.
the Next button.
next screen asks you which fields you want on the report. Click on the
following fields and move them to the Fields To Display list by clicking on the
> button. Product.ProductNumber, Product.ProductName, SalesOrderDetail.OrderQty,
SalesOrderDetail.UnitPrice, and SalesOrderDetail.LineTotal.
the Next button.
next screen asks you to group the records. There is no grouping in the
subreport since this is handled in the main report. Simply click the Next
next screen asks you for the selection criteria. There are no selection
criteria for this report. This will be handled in the main report. The
SalesOrderID field will be passed to this report and only records for the
specified ID will be displayed. Click the Next button.
report style will be standard so leave Standard selected and click the Finish
will bring you back to the Insert Subreport dialog. Click on the Link tab.
screen allows you to define the field that will link the two reports together.
Select the SalesOrderHeader.SaleOrderId from the Available Fields list and
click the > button.
parameter field will be created in the subreport that will contain the
SalesOrderID from the main report. Click the OK button.
SalesOrderDetail subreport will be displayed as a box in the details section.
Click on the box to show the window handles and drag the borders so they are
the width of the page.
default the subreport is shown with a box around it. For this report we want
to remove the box. To do this, right click on the subreport and select Format
Object from the pop-up menu.
Format Editor dialog box will appear. Click the Border tab and set the Left,
Right, Top, and Bottom border to None and click the OK button.
Section1(Report Header), Section2(Page Header), GroupFooterSection1,
Section1(Report Footer), and Section5(Page Footer). You can hide the section
by right clicking the gray bar and selecting Suppress from the pop-up menu.
you can preview the report by clicking on the Main Report Preview button.
Step 5: Format the Subreport
As you can see from the preview, the print date is being
repeated in the sub report and there is extra space between each group. This
is because when the sub report was created Crystal included the print date in
the report and also shows extra sections in the subreport. You can modify the
subreport to not show the print date and hide the extra sections by following
Click the Main Report button.
Right click on the subreport and select Edit Subreport from the pop-up
The SalesOrderDetail subreport will now be displayed and an extra button
will appear next to the Main Report Preview button that allows you to toggle
back and forth between each view.
Click on the Print Date field in the sub report and press the delete key
to remove it.
Lasso all the column header fields and drag them to the top of the
Make the PageHeader height smaller by hovering your mouse over the top
of the details gray bar until the pointer turns to a vertical bar. Click and
drag the bar to just below the column header text boxes.
Right click on the ReportFooter2 gray bar and select Suppress from the
Right click on the LineTotal field in the Details section and select
InsertàSummary… from the pop-up
Leave the default settings and
click the OK button. This will add a total field to
ReportFooterSection1(Report Footer a) and unhide the section.
Click on the Main Report Preview button to display the report.
The report is now displayed correctly without the print date
and the extra spacing for the sections.