Monday 25 February 2008

To Subreport or Not to Subreport (Crystal Report)

I don't know whether there is a general rule about when to use subreports. Many times you will see people recommend against the use of subreport because they slow reports, and in general, they are right, but there are some cases when using a subreport actually speeds up reports. Some cases when subreports make sense:

1-To avoid a geometric increase in records due to joining multiple tables that have one to many or many to many relationships. If you have two tables joined by an ID field and there are two or more records in the first for each ID, then if you join it to a table with two or more records per ID, the records from the second table would repeat for each record in the first table. Instead you can use a subreport for the second table, place it in a group header for a group based on ID, link the subreport to the main report by ID, and the display will be limited to one set of records for the second table.

2-To show a limited set of information in the report header. For example, to show description fields for a parameter based on a numerical value.

3-To link data from two different datasources that otherwise cannot be linked, because CR doesn't support the the use of multiple datasources in the visual linking expert, e.g., data from an Excel database and from an Oracle database.

4-To link data from two tables where one field is of a different datatype or length and therefore must be converted by formula in order to be linked to a second table. Again, you can't do this in the visual linking expert, but you can link a formula and a field in the subreport links.

5-Subreports also can help in complex reporting situations--
charting on print-time formulas, creating ranks of data without sorting the displayed data, grouping on the number of records on a page, limiting the vertical display of multiple column data, etc.

6-To display a summary report that displays summary data from many different analyses based on different datasets or based on different selection criteria.

7-On-demand subreports can be used to display detail on an as-needed basis.

8-To display data from two tables where there are no fields that can be linked.

9-To allow the sequential display of all records from one table, followed by all records from another.

10-To create multiple copies of the same data, e.g., on different pages.

11-To allow drill-down on each of several values in the same row.

This is all I can think of for now. Subreports are sometimes very useful, and even essential in many situations. Besides the (usually) slower speed caused by subreports, another downside is that to use subreport data in calculations in the main report, you have to use shared variables, which can become quite complex.

Share:

0 comments:

Post a Comment