Defining queries

A query is a SQL SELECT statement created in the Query painter and saved with a name so that it can be used repeatedly as the data source for a DataWindow object.

Queries save time, because you specify all the data requirements just once. For example, you can specify the columns, which rows to retrieve, and the sorting order in a query. Whenever you want to create a DataWindow object using that data, simply specify the query as the data source.

StepsTo define a new query:

  1. In the Solution Explorer, right-click the library where you want to save the query object and select Add New Entry.

  2. In the Add New Entry dialog box, select Query from the categories list.

  3. Provide a name for the query object and click Add.

    The query name can be any valid DataWindow Designer identifier up to 40 characters. When you name queries, use a unique name to identify each one. A common convention is to use a two-part name: a standard prefix that identifies the object as a query (such as q_) and a unique suffix. For example, you might name a query that displays employee data q_emp_data. For information about DataWindow Designer identifiers, see Appendix A, “Identifiers.”

  4. Select tables in the Select Tables dialog box and click Open.

    You can select columns, define sorting and grouping criteria, define computed columns, and so on, exactly as you do when creating a DataWindow object using the SQL Select data source.

For more about defining the SELECT statement, see “Using SQL Select”.