
• To select a stored procedure as a data source, see "SQL stored procedures" in the online help.
6.5 Using enhanced record selection formulas
The most important thing you can do to speed up report processing is to limit the amount of data that
is returned from the database. Your primary tool for doing this is the record selection formula.
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.
6.5.1 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
2011-05-16119
Designing Optimized Web Reports
urenrjrjkvnm
Cinema