In this section we will illustrate how to use Excel's MS Query to build a query which we will then insert into an OpenRPT report definition to generate a report. Below is the final SQL generated by MS Query using our ODBC connection to the usr
table in our xTuple database:
SELECT usr.usr_id, usr.usr_username, usr.usr_propername, usr.usr_passwd, usr.usr_locale_id, usr.usr_initials, usr.usr_agent, usr.usr_active, usr.usr_email FROM public.usr usr ORDER BY usr.usr_username
Now we will show the steps involved to generate the predefined query.
First, open the Excel application. From the
menu select the option. Then select the option. You will be presented with the following screen:Select the new ODBC connection you just created against your PostgreSQL database, and then click the
button.In the left column, scroll to the table usr
and click on it. Then select the button to select all columns in the table. Finally, select the button to be brought to the following screen:
Next, the Query Wizard provides you with the opportunity to filter the data. For this exercise, we will choose not apply a filter to the data. Click the
button to reach the following screen:We will define one sort criteria. In the Sort by field select the column usr_username
and check Ascending next to it. Click the button to reach the next screen:
Since we are only using query to generate an SQL statement, we check the option View data or edit query in Microsoft Query. Click the button.
Initially, Microsoft Query displays the results of the query we just created with the Query Wizard. To see the syntax of the SQL statement, click the
in the toolbar.To copy this SQL statement for importing into an OpenRPT report definition, select the statement and then right click and use the
option. Later you can paste the statement into an OpenRPT query source.Earlier chapters in this user guide covered the details of modifying and creating OpenRPT report definitions. The next few screens show the core elements of a report definition and the resulting output.
Above you can see the SQL statement exactly as it was copied from Microsoft Query and pasted into an OpenRPT query source for a new report definition. We will run this report using the xTuple application—and so we will save it with the already-existing report definition name "UsersMasterList". To distinguish this version of the report from others, we will assign this version a grade of "20". In xTuple, report definitions having the highest grade are used. Assuming "20" is the highest grade for UsersMasterList, our new version will be run with users. Select
from the xTuple master list of users.The SQL in our example is the exact same SQL statement as it was copied from Microsoft Query. MetaSQL has not been added to it. When printing the User master list from xTuple, the client passes the parameters locale_id
and showInactive
to the report definition at run time. These parameter values can be used to create sophisticated WHERE
clauses that show data on the report based on user entries on the User screen. Remember, you can use the MetaSQL editor to test SQL that contains MetaSQL before pasting into a report's query source. MetaSQL is covered in another chapter of this user guide.
Below is a look at the report definition we created using the query we built with Microsoft Query.
This report definition will be run when an xTuple user selects
on the following xTuple screen:After we select
, the report definition is printed just as we planned:The report shown above was generated using the SQL we copied from Microsoft Query. It demonstrates the speed and ease with which new reports can be created and deployed using OpenRPT.