To create an SQL query string using QBE

  1. Select Option from the menu bar. A drop down list appears.

  2. Select Query by Example Interface from the drop down list. The Create QBE Wizard Introduction dialog box appears.

  3. Click the Next button. The Choose Table(s)/Column(s) dialog box appears.

  4. You can choose one table/view or multiple tables/views from the Table Name drop down list. When you specifying a table or view, the columns contained in the selected table(s)/view(s) appear in the panel to the left in the dialog box.

  5. When the list of available columns on the selected table/view appears on the left hand list box. Select columns by double clicking on the column name or selecting the column and clicking the Add button. The Add all button can be used to add all columns to the replication. All the selected columns will be displayed in the list box to the right. Columns can be likewise removed from the replication by double clicking on the column name or selecting the column and clicking the Remove button.

  6. NOTE To select multiple columns hold down the Ctrl key and use the mouse to select the columns.

  7. Click the Next button. The Adjust Selected Column's Order dialog box appears.

  8. Enabling the Use wildcard setting can help user to fetch all table records using wildcard.

  9. Remove duplicate record option:

    1. To fetch all records by default mean, select the Default (ALL) option button.

    2. To fetch data flexible, select the Distinct option button. Example, if a table has some duplicate data record, using Distinct option can remove those duplicate data records when SQL query be executing.

  10. To expand the table to view all the available columns double click the table or click the expanding icon ( ) at the side of table name.

  11. Select a column from the column list, the selected column is highlighted, user can right-click it, it will pop-up a menu to let user set one aggregate function or remove it from the projected column. QBE support five aggregate functions: AVG/COUNT/MAX/MIN/SUM

  12. DBMaker support UDF functions, QBE can apply them into projected columns or where clause column compare. Click the Add UDF button to launch the following dialog.

    1. Column Name and Column Type fields show the selected column's name and type.

    2. Select a UDF from the Match Function Name drop down list, the selected UDF appears in the Description area. To explain the UDF more clearly, there have some examples in the Example area.

    3. Click OK.

  13. Click the Modify UDF/Remove UDF buttons to modify or remove the selected UDF function.

  14. Click the Setting button. The Projected Column Operation window appears.

    1. You can choose one operator from the Operator drop down list.

    2. Choose one column from the Table(alias).Column drop down list.

    3. Click the Add button. The operation appears in the Preview area below of the window.

    4. Use the Up, Down, Remove buttons to adjust the selected column's order.

    5. Click OK.

  15. Double click the Alias Name field for a column to specify an alias name.

  16. Select a column from the Table/Column field using the mouse. The selected columns will be highlighted. Click the Up, Down or Remove button to adjust or drop the selected column.

  17. Click the Next button. The Where Clause window appears.

  18. To set a Where clause:

  19. Select a column from the Table(alias).Column(alias) drop down list on the left.

    1. Select an operator from the Operator drop down list. QBE support following operators: =, >, <, >=, <=, <>, +, -, *, /, ||, between, is null/is not null, in/not in, like/not like, match/not match, contain/not contain.

    2. Enter a value in the Table(alias).Column(alias) field on the right or select a column from the drop down list.

    3. Click the Add button, the where condition appears in the panel below of the window.

  20. NOTE If some selected tables have a PK/FK relationship, QBE will make the default PK/FK relation a where condition.

  21. If you want to add a UDF function, you can click the Import button ( ) on the right of the Table(alias).Column(alias) field to add a UDF function.

  22. Click the Export button ( ) to cancel the selected UDF function.

  23. The QBE interface supplies you with ten functions:

    1. Up: Moves the condition item from the current position to the previous position.

    2. Down: Moves the condition item from current position to the next position.

    3. Remove: Removes the selected condition item.

    4. AND: Adds an AND operator into the next position

    5. OR: Adds an OR operator into the next position.

    6. NOT: Adds a NOT operator into the previous position.

    7. +(: Adds a left bracket into the previous position.

    8. +): Adds a right bracket into the next position.

    9. +(): Adds brackets into the selected condition item.

    10. -(): Removes brackets from the selected condition item.

  24. Click Next. The Group by Clause window appears.

  25. Select columns to use Group By Clause. A group is a set of rows that have the same values of group by columns. A single row of aggregate results is produced for each group.

  26. Click Next. The having clause window appears. From this window the user can refer to steps 12-16 for details.

  27. Click the Next button when you are satisfied with the clauses. The Order by Clause window appears.

  28. Select the sort order for the columns using the Order by Clause dialog box. The order by clause can sort query results by the values contained in selected columns.

  29. Click the Next button. The Building SQL Review dialog box appears. QBE make a SQL script automatically, you can modify it manually. For the final SQL, you can save an external file, create it as stored command, create it as view or preview the execution SQL result.

  30. To save the query:

    1. Click the Save button. The Save dialog box appears.

    2. Enter a name and location for the query in the dialog box and click the Save button.

  31. To create the query as a stored command:

    1. Click the Create as stored command button. The Input stored command name dialog box appears.

    2. Enter a name in the Stored command name field.

    3. Click OK. A message saying the stored command is created successfully is displayed.

    4. Click OK. The created SQL command saves as stored command appears in the stored command list.

  32. To preview the query:

    1. Click the Preview button. The Preview QBE Result dialog box appears.

    2. Browse the results using the scroll bars. For large results use the Page Up, Page Down, First and Last buttons.

  33. To create a view on the query:

    1. Click the Create as view button. The Input View Name dialog box appears.

    2. Enter a name for the view in the View name field.

    3. Click OK. A message saying the view is created successfully is displayed.

    4. Click OK.

  34. Click Previous to return to prior windows or click the Close button when you are satisfied with the QBE


Related topic:

Query By Example (QBE)