Pushing down record selection—an example – HP Intelligent Management Center Standard Software Platform User Manual

Page 178

Advertising
background image

Crystal Reports analyzes your record selection formula and generates an
SQL query from it. This SQL query is then processed by the database, which
sends the resulting records back to Crystal Reports. Crystal Reports then
evaluates the record selection formula locally for each of the records retrieved
from the database, thereby calculating the set of records used to generate
the report.

Unnecessary records are eliminated at two stages: at the database with the
SQL query and within Crystal Reports by the record selection formula. For
speed, you want as many records as possible to be eliminated in the first
stage. By designing your record selection formula effectively, you can off-load
much of the processing to the database server, thus eliminating unnecessary
records before returning them to Crystal Reports. This is commonly called
"pushing record selection down to the database server."

This section offers several tips to ensure that your record selection formulas
can be pushed down to the database server.

Pushing down record selection—an example

This example demonstrates the benefits of writing record selection formulas
that can be pushed down to the database server.

In the Orders table of the Xtreme sample database, there are 2192 records,
of which 181 have order dates prior to 2001. Suppose you want to report on
only those records. On the one hand, you could use this record selection
formula:

Year ({Orders.Order Date}) < 2001

The SQL query generated will send all 2192 records to Crystal Reports, and
then the record selection formula will reduce this to 181. To see this, click
Show SQL Query on the Database menu and notice that the SQL query has
no WHERE clause. This is because Crystal Reports is not able to push down
the Year ( ) function in the WHERE clause.

On the other hand, this record selection formula generates the same report:

{Orders.Order Date} < #Jan 1, 2001#

This second formula, however, can be performed on the database server,
so it is pushed down. The SQL query generated will send only 181 records
to Crystal Reports. So, when the record selection formula is evaluated by

178

Crystal Reports 2008 SP3 User's Guide

Designing Optimized Web Reports

8

Using enhanced record selection formulas

Advertising