|
1 | 1 | --- |
2 | 2 | title: Query Builder |
3 | 3 | --- |
4 | | -# Query Builder |
| 4 | + |
| 5 | +# SQL Query Builder (WinForms) |
| 6 | + |
| 7 | +The **Query Builder** allows you to construct SQL queries to retrieve data from an [SQL Database](TODO). |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +## Run the Query Builder |
| 12 | + |
| 13 | +Use the [Data Source Wizard](TODO) or [Report Wizard](TODO) to bind your report to an [SQL Database](TODO). Switch to the [query customization page](TODO) and click the *Add* button in the **Queries** row. |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +## Select Tables |
| 18 | + |
| 19 | +Drag the table that you want to add to a query from the list of available tables and drop the table onto the **Query Builder** surface. |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +To find a table by name, switch to the table list, press *CTRL+F*, and enter the table name in the editor. |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +Enable checkboxes for the table columns that you want to include in the query. |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +If you want to include all the columns available in the table, enable **\* (All Columns)**. |
| 32 | + |
| 33 | +Right-click the table and select *Rename* or *Delete* to change the table's name or remove it. |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +## Join Tables |
| 38 | + |
| 39 | +You can join multiple tables within the same query. Do one of the following to add a table onto the **Query Builder** surface: |
| 40 | + |
| 41 | +- Drag and drop a table from the table list onto the surface. |
| 42 | +- Double-click a table in the table list. |
| 43 | + |
| 44 | +The table list on the left highlights all child and parent tables that are bound to the dropped table by a foreign key. |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +Add required tables to the surface. The *Inner Join* relation with the previously added table is created automatically. Added tables display the green plus button for the columns that refer to other tables. You can click this icon to add a linked table to the query and create the *Inner Join* relation with this table. |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +Right-click a relation to edit, delete, or reverse. |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +The *Edit Relation* command invokes the **Join Editor**. It allows you to specify the join type (*Inner*, *Left Outer*, *Right Outer*, or *Full Outer* ), columns by which the tables should be joined, and a logical operator (*Equal to*, *Is less than*, or others) used to compare table columns. |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +You can manually join tables if they are not bound by a foreign key at the database level. In this case, when you drag-and-drop a table onto the **Query Builder** surface, the **Join Editor** is automatically invoked, and this editor allows you to construct a custom join relation. |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +> [!NOTE] |
| 65 | +> When you join multiple tables within a single SQL query, you create a flattened table composed of data records selected based on the specified join relations. You can also create [hierarchical data sources](TODO). In general, [master-detail reports](TODO) are generated faster than similar-looking reports created based on flattened data sources. If possible, use hierarchical data sources instead of flattened ones. |
| 66 | +
|
| 67 | +## Shape Data |
| 68 | + |
| 69 | +The **Query Builder** displays a list of the query's columns at the bottom-right corner. |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +This list allows you to add new table columns to the query or shape selected table columns. The following options are available: |
| 74 | + |
| 75 | +* **Column** - Specifies the selected column. Click the down-arrow button to display a drop-down column list and replace the column with another column. Click the ellipsis button to replace the column with an [expression](TODO). |
| 76 | + |
| 77 | +  |
| 78 | + |
| 79 | +* **Table** - The table that contains the selected column. When you create an expression for a column, this option displays **(All Tables)**. |
| 80 | + |
| 81 | +* **Alias** - A custom column name. |
| 82 | + |
| 83 | +* **Output** - Specifies whether to include the column in the query's resulting set. |
| 84 | + |
| 85 | +* **Sorting Type** - Specifies whether to keep the initial data record order (**Unsorted**) or sort the records by the column (**Ascending** or **Descending**). |
| 86 | + |
| 87 | + > [!NOTE] |
| 88 | + > When you bind a report to an XML file, the **Query Builder** does not support sorting by aggregate functions, the *DISTINCT* and *SELECT ALL* statements, and manual SQL editing. |
| 89 | + |
| 90 | +* Sort Order - Defines the sort order when data is sorted by multiple columns. For example, if column **A** has the sort order set to **1** and column **B** has it set to **2**, data records are first sorted by column **A** and then by column **B**. This option is available if you enable the **Sorting Type** option. |
| 91 | + |
| 92 | +* **Group By** - Specifies whether to group the query's resulting set by this column. |
| 93 | + |
| 94 | +* **Aggregate** - Specifies whether to apply an aggregate function to column values. The following aggregate functions are supported: |
| 95 | + |
| 96 | + * Count |
| 97 | + * Max |
| 98 | + * Min |
| 99 | + * Avg |
| 100 | + * Sum |
| 101 | + * CountDistinct |
| 102 | + * AvgDistinct |
| 103 | + * SumDistinct |
| 104 | + |
| 105 | +When you want to use the **Group By** or **Aggregate** operations, you should apply them either to all columns or none of them. When you use these operations, only the result of aggregation or grouping is included in the result set. |
| 106 | + |
| 107 | +## Filter Data |
| 108 | + |
| 109 | +Click the **Filter** button to invoke the **Filter Editor**. |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | +The editor has the following tabs: |
| 116 | + |
| 117 | +* **Filter Tab** - Allows you to build criteria to filter data for the report. Filter criteria can reference [query parameters](TODO), which you can also map to [report parameters](TODO). |
| 118 | +* **Group Filter Tab** - Allows you to specify filter conditions for grouped and aggregated data. This tab is disabled if the data is not grouped. |
| 119 | + |
| 120 | +You can also enable the **Select only** option to limit the number of resulting data records. If you enable the **Sorting Type** option for at least one column, you can specify how many data records should be skipped. |
| 121 | + |
| 122 | +> [!NOTE] |
| 123 | +> Some data providers do not support the skip setting in the provider-specific SQL string. If you enable the **Select only** option for such data providers, data records are skipped but the *SKIP* statement is not included in the SQL query. |
| 124 | +
|
| 125 | +The **Select only distinct values** option allows you to include only unique values into the resulting set. |
| 126 | + |
| 127 | +## Edit Query Parameters |
| 128 | + |
| 129 | +Click **Edit Parameters** to invoke the **Query Parameters** dialog. |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +This dialog allows you to add, edit, and remove [query parameters](TODO). The created parameters are available on the [Configure Query Parameters](TODO) wizard page. |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | +The following properties are available for each query parameter: |
| 138 | + |
| 139 | +* **Name** - The name by which you can reference the parameter. |
| 140 | + |
| 141 | +* **Type** - The data type of the parameter's value. |
| 142 | + |
| 143 | +* **Expression** - Specifies whether the parameter's value is static or generated dynamically. You can enable this option when you need to map the parameter's value to a [report parameter](TODO)'s value. |
| 144 | + |
| 145 | +* **Value** - The parameter's value. If the **Expression** option is enabled, this value is generated dynamically based on the parameter's [expression](TODO). |
| 146 | + |
| 147 | +Refer to the following topic for more information: [](TODO). |
| 148 | + |
| 149 | +## Preview Results |
| 150 | + |
| 151 | +Click the **Preview Results** button to open the **Data Preview** dialog. |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | +The dialog displays the first 1000 rows of the query result set. |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | +## Manage Queries |
| 160 | + |
| 161 | +Right-click a data source in the [Report Explorer](TODO) or [Field List](TODO) and select **Manage Queries** in the context menu. |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +This invokes the **Manage Queries** dialog that allows you to perform operations on queries and stored procedures. |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | +### Add a New Query |
| 170 | + |
| 171 | +Click **Add**, specify a name for the new query, and [select tables](#select-tables) that you want to include in the query. |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | +### Copy and Remove Queries |
| 176 | + |
| 177 | +Select a query and click the *Copy* or *Remove* icon. |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | +### Modify Stored Procedures |
| 182 | + |
| 183 | +Select an existing stored procedure and choose a new one that you want to include in a query. |
| 184 | + |
| 185 | + |
| 186 | + |
| 187 | +### Add a New Stored Procedure |
| 188 | + |
| 189 | +Expand the **Add** menu and select **Stored Procedure**. |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | +### Rename a Query or Stored Procedure |
| 194 | + |
| 195 | +Double-click an item in the list of queries and stored procedures and use the editor to specify a new name for this item. |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | +# Query Builder (Old) |
5 | 200 |
|
6 | 201 | The **Query Builder** provides a visual interface for constructing SQL queries used to access database tables and views. |
7 | 202 |
|
|
0 commit comments