The New Record Wizard: Edit Query

Edit the query used to extract and order the data from your database.

Figure: Query Creation (New Record Wizard)

Screen shot of Query Creation page.

The Query Creation page assists you in defining the SQL query that is used to extract the data from the database. The SELECT list has already been defined by the Column selection page, the remaining parts of the SQL query.

Specify the join clause

The join clause defines how the tables relate to each other. If the meta-schema includes the primary-foreign key relationships between the tables, this section is auto-populated with the correct join criteria.

If the relationships are not defined by the meta-schema, or if you are using a join other than an inner join, you may need to create or modify the join criteria.

When selecting the type of join, you can choose between INNER JOIN, FULL OUTER JOIN, LEFT OUTER JOIN or RIGHT OUTER JOIN. Refer to your database vendor for details on the different types of joins and how they are handled by the database.

Add additional tables

While not typical, you can add additional tables to your query, and you can specify an alias for the tables you add.

Reasons for adding additional tables:
  • You may be adding a WHERE condition that includes tables whose columns were not part of the column selection. For example, your may have only asked for columns from the customer and items table, but if the orders table is required to enable the join between the customer and items table, you must add it here.

Specify a WHERE clause

The WHERE clause is the filter that determines which rows answer the query. If a query does not specify a WHERE clause, then all data is returned from the table(s). Use the Where field to enter SQL that applys selectivity to the rows returned from the database.

Define the ORDER BY clause

The Order by criteria defines two things:
  1. How the data is ordered.
  2. How the data is grouped.

The Order by section is not populated for you by default.

For the Genero Report Writer, the Order by section sets the report triggers for your data schema. A trigger allows the report design to place a report object (such as a subtotal or a section header) when leaving one group of data and starting the next group of data.

For example, consider a data model about accounts and their orders. The account table has a unique field, account_id, that also serves as its primary key. The order table also uses the account_id to map an order to an account. We order by account_id, because we want the data sorted by account, and we want to provide group-level information on the account level. A trigger is created for the account_id, and when the data is streaming, a change to the value of the account_id signals the move from one group of data to the next. The trigger can indicate to print a report section: subtotals, section headers, and so on.

The order of the tables referenced in the Order by section tend to go from the general to the specific. For example, if you have accounts, orders, and regions, you state:
  • A region contains many accounts
  • An account has many orders

In the Order by section, you first specify the region table (with a unique column, such as region_id), and then specify the account table in the second row (with a unique column, such as account_id). While it is typical to use the primary key column in the Order by section, it is not necessary. However, the column must be unique.

Custom SQL

On the Custom SQL tab, you can select the Override checkbox and handwrite the FROM and WHERE clause for the query. This allows for the creation of complex SQL that may otherwise not be generated by a wizard.

Important: The custom SQL should be limited to FROM and WHERE clauses. Do not alter the column list with a SELECT clause, and do not include an ORDER BY clause.