View on GitHub

dotnet-eud

.NET Controls End-User Documentation

Query Builder

The Query Builder provides a visual interface for constructing SQL queries used to access database tables and views.

query-builder

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

Run the Query Builder

You can invoke the Query Builder from the query customization page of the Report Wizard. On this page, click the report-wizard-multi-query-page-icon-add button for the Queries category to create a new query using the Query Builder.

eurd-win-report-wizard-invoke-query-builder

You can 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 or Field List, and select Manage Queries… in the context menu.

report-explorer-field-list-manage-queries

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

query-designer-query-collection-editor

Finally, click the Run Query Builder… button in the invoked Query Editor.

Select Tables

You can add a specific data table or view to a query by dragging the corresponding item from the list of available tables and dropping it onto the list of data tables to be used.

query-builder-diagram-drop-table

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

query-builder-diagram-select-fields

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

query-builder-diagram-table-context-menu

Click the list of available tables on the left and press CTRL+F to search for a specific table or view.

query-builder-search-table

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 you added a main table to include it in a query and automatically create an inner join relation based on a key column.

query-builder-diagram-join-tables

Alternatively, you can join tables by clicking the plus button QueryBuilderPlusButton in a row corresponding to a key column.

You can customize the relationship by right-clicking it on the diagram and selecting Edit Relation in the invoked context menu. Use the Join Editor to select the join type (Left Outer or Inner), apply a logical operator (Equals to, Is less than, etc.) and column key fields.

query-builder-diagram-join-editor

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

When the left outer join is selected, the relationship line displays an arrow pointing to the “right” table.

query-builder-diagram-left-outer-join

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

After executing the query, it returns 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.

query-builder-diagram-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 and ways of providing parameter values, 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.

query-designer-filter

Shape Data

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

query-builder-column-list-shaping-data

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

Preview Results

You can preview the query execution’s result in a tabular form by clicking the Preview Results button.

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

query-designer-preview