View on GitHub

dotnet-eud

.NET Controls End-User Documentation

Query Builder

The Query Builder provides a visual interface for constructing SQL queries and enables you to solve a variety of tasks.

wpf-designer-query-builder

[!NOTE] The Query Builder is not available for object, Entity Framework and Excel data sources.

The document consists of the following sections.

Run the Query Builder

You can invoke the Query Builder from the query customization page of the Report Wizard when creating a new data-bound report or when binding an existing one to a database. To do this, select the Query item and click the Run Query Builder button.

wpf-report-wizard_run-query-builder

You can also use the Query Builder to add queries to an existing SQL data source, as well as to edit existing queries. To do this, right-click the data source in the Report Explorer and select Manage Queries in the context menu.

wpf-designer-sqldatasource-manage-queries

In the invoked Manage Queries dialog, click Add to add a new query. To edit an existing query, click the ellipsis button.

wpf-desinger-manage-queries-dialog

Finally, click the Run Query Builder button in the invoked Data Source Wizard.

Select Tables

To add a specific data table or view to a query, drag the corresponding item from the list of available tables and drop it onto the list of data tables to be used.

wpf-designer-query-builder-add-table

Enable check boxes for the table fields that you want to include in the query result set.

wpf-designer-query-builder-select-fields

Each table provides the context menu, which allows you to rename the table or remove it from the query.

wpf-designer-query-builder-table-context-menu

To search for a specific table or view, click the list of available tables on the left and start typing the search name.

wpf-designer-query-builder-search-tables

Join Tables

You can join multiple tables within the same query. The Query Builder automatically highlights tables related to any of the previously added tables. Drag-and-drop a subordinate table in the same way as a principal table to include it in a query and automatically create an inner join relation based on a key column.

wpf-designer-query-builder-join-tables

Another way to join tables is to click the wpf-designer-query-builder-add-button button in a row corresponding to a key column.

To customize the relationship, click the corresponding ellipsis button. Use the Join Editor to select the join type (Left Outer or Inner), applied logical operator (Equals to, Is less than, etc.) and column key fields.

wpf-designer-query-builder-join-editor

A left outer join returns all the values from an inner join along with all values in the “left” table that do not match to the “right” table, including rows with NULL (empty) values in the key field.

If tables do not have a relationship at the database level, you can manually join tables. In this case, when you drag-and-drop the required table onto the list of tables to be used, the Join Editor is automatically invoked allowing you to construct a custom join relationship.

After executing the query, it will return a “flat” table composed of data records selected based on the specified join options.

[!NOTE] Although joining different tables within a single query may be required in some scenarios, creating hierarchical data sources generally results in better performance (in general, master-detail reports are generated faster than similar-looking reports created by grouping “flat” data sources).

Edit Parameters

Click the Edit Parameters button to invoke the Query Parameters dialog, which allows you to add and remove query parameters as well as specify parameter settings.

wpf-designer-query-builder-query-parameters

For each query parameter, the following properties are available.

The created parameters will be then available on the Configure Query Parameters wizard page.

For general information on query parameters, see Query Parameters.

Filter Data

To specify filter criteria, click the Filter… button in the Query Builder. This invokes the Filter Editor, which provides the following capabilities.

wpf-designer-query-builder-filter-editor

Shape Data

The Query Builder displays the column list under the data source editor, which provides various shaping options.

wpf-designer-query-builder-column-list

The following options are available.

[!NOTE] You should apply aggregation/grouping to either all columns or to none of them.

Enable Custom SQL Editing

If custom SQL editing is enabled by your software provider, the Query Builder contains the Allow Edit SQL check box. Selecting this option disables the visual features of the Query Builder and allows users to specify the custom SQL string manually.

wpf-designer-query-builder-allow-edit-sql

Preview Results

You can preview the result of the query execution in the form of a tabular data sample by clicking the Preview Results button.

This opens the Data Preview window displaying the query result set limited by the first 1000 data records.

wpf-designer-query-builder-data-preview