Master-Detail Reports With SQL Data Views

Category

Rave - General

Question

How do I create a Master-Detail report with SQL Data Views?

Solution

The fundamental process for creating master-detail reports requires linking data bands by setting the MasterDataView, MasterKey, and DetailKey properties on the detail band (as well as its Detail property). If the data views involved are SQLDataViews, however, and additional step is required, whereby the underlying queries are linked through a parameter. If you've ever created linked queries in Delphi or C++, the modification of the detail query will be familiar.

Suppose we wish to create a master-detail report listing customers and their orders, out of the DBDEMOS database. To do this we create a datbase component, and then a Customers SQL Data View (name: CustomersDV) and an Orders SQL Data View (name: OrdersDV connected to this database. The core query text for these data views would be:

Customers: SELECT C.* FROM CUSTOMERS C
Orders: SELECT O.* FROM ORDERS O

In order to allow the report to show the correct detail with a given master row, however, we must add an SQL parameter to the detail query text, one specifying the master row key:

Orders: SELECT O.* FROM ORDERS O WHERE O.CUSTNO = :CUSTNO

Then, using the Parameters tab of the SQL Property Editor for the Orders SQL data view, we add a parameter specification which instructs RAVE where to find the SQL parameter value when the detail query is opened:

CUSTNO = CustomersDV.CUSTNO

Note the format here: an SQL parameter name (without the ":" prefix), an equals sign as an assignment operator, followed by a data view field specification of the form

<SQL Data View Component Name>.<Query Field Name>

Once the data views have been properly set up, construction of the report proceeds precisely as if you had based it on direct data views. Note also that, if you use Rave's Master-Detail Report Wizard to construct the report, the Wizard will not link the queries automatically for you.