How to create SQL queries with SQL Builder

By: Borland Staff

Abstract: Here is a quick walk-through of creating a query with SQL Builder

Problem:
Here is a quick walk-through of creating a query with SQL Builder.  SQL Builder is an interactive
tool that is included with Delphi and C++ Builder.   It allows a user to create an SQL query using 
a graphical interface.   Complete instructions on displaying results using a dbGrid component is 
also covered.


Solution:
*******************************************************************************
Note: The information in this document was tested with C++ Builder 3.0.
*******************************************************************************


A.  Setup Display Components
=========================
1. File | New Application

2. Click on the Data Access tab.

3. Click on the Query icon and then on form to place Tquery component on the form.

4. Hit  to go to the Object Inspector.

5. Click on space next to DatabaseName.

6. Select the alias you will be using from the pull down menu,
    For this example, we will use the "DBDEMOS" alias that ships with the BDE.

7. Click on DataSource icon and then on form to place DataSource on the form.

8. Hit  to go to the object Inspector.

9. Click on the space next to the "DataSet" property.

10.  Enter "Query1" (without the quotation marks) as the DataSet.

11. Click on Data Controls tab.

12. Click on DBGrid icon and then on the form.

13. Hit  to go to the Object Inspector.

14. Click on space next to the "DataSource" property.

15. Click on downarrow and select "DataSource1".


B. Set Up Query
==============
1. Right click on query component.

2. Select SQL Builder from menu.

3. Click on  down arrow next to "Table" drop down list.

4. Select "customer" from the list.

5. See the list of fields in customer table appear in a box.

6. Click on checkbox  next to the table name.

7. Notice that this checks all the fields.

8. If you hit the SQL button at this time, you can see the SQL statement that was generated for you.

9. Click on File | Exit to get out of the SQL Builder.

10.     When prompted to save changes to the query, click on "Yes"

11.    Your SQL query is now built and stored in the tquery component. 
       You can see that the query got built by looking at the SQL property
       of the Tquery component. 

12. To see the results of the query, you will need to set the active property on the
      Tquery to true.  Here are the steps to do that:
                        a. Right click on the tquery component
                        b. Hit  to get to the Object Inspector.
                        c. Click on space next to Active property.
                        d. Select  True  from the list.

11. Hit  to run the form.   You will see the results of your query in a grid.


Server Response from: ETNASC03