Using the Query Builder

in Toad for Data Analysis
written by Shawn Pickett, Senior Developer and Alan Bala, Development Team Lead, Quest Software, Inc

....................................................................................................... 13 CONTACTING QUEST SUPPORT.............................. 5 FORMULAS ...................................................................... 6 SUBQUERIES ....................................................................................................................... 7 DATE RANGES .............. 13 CONTACTING QUEST SOFTWARE ............................... 9 QUERY LIMITATIONS...................................................................................................... 3 THE QUERY BUILDER CONTROL .................. INC. 5 USING BIND VARIABLES ......................................................................................................................................................... 12 ABOUT QUEST SOFTWARE..........................................................................................................................................................................Query Builder – Overview Table of Contents QUERY BUILDER OVERVIEW ............................................................................................................................................ 4 WORKING WITH THE QUERY BUILDER .......................................................... 13 Page 2 of 13 ............... ...................................................................................................... 4 DEFAULT SETTINGS................................................................. 8 HETEROGENEOUS QUERIES ......................................................................................................................................................................................... 10 REVERSE ENGINEERING LIMITATIONS ..... 6 DISTINCT VALUES ..................... 3 SAVING FILES ................................................................................................ 7 LOOKUP TABLES ........................................................................................... 10 REVERSE ENGINEERING .................................................................................................................................................................................................................................................................................

The Query Builder is an efficient and easy way to visually create SQL queries. Tables and views can be added either by dragging and dropping the object to the pane or by right-clicking on the selected object and selecting the Send To menu option: Send To  Query Builder.htm Page 3 of 13 . you can also access the Query Builder by clicking on the Query tab on the Wizard bar. The Query Builder Control A Flash Demo of the Query Builder can be viewed here: http://toadworld.com/Portals/0/assets_ifs/flashdemos/TDA-QueryBuilder/index.Query Builder – Overview Query Builder Overview This document offers guidelines and guidance to help you use the Toad for Data Analysts Query Builder. In Toad for Data Analysts.

This xml format file contains all the information needed to restore the saved state including all the objects. From here you can choose to fully qualify object and column names and limit the number of objects added to the control. Checking Use fully qualified column names will fully qualify the column name in the form of table. The file save menu can be found by right-clicking on the Query Builder document tab or from the main menu under File  Save File when a Query Builder document tab is selected. Default Settings The Query Builder options are accessible from the main menu under Tools  Options Database  Query Builder and from main menu under Query Builder Query Builder Settings when the Query Builder is open.column. where conditions. joins.Query Builder – Overview Saving Files Query Builder files are saved and can be identified with the *. Page 4 of 13 .table. Checking Use fully qualified object names will fully qualify the object name with schema in the form of schema. positioning etc… of the Query Builder control. The default of limiting the maximum number of objects to 50 was selected to limit impact on the database and for optimal application responsiveness.tsm file extension.

Query Builder – Overview Working with the Query Builder Using Bind Variables The use of bind variables is supported when you specify the query criteria in the Query Builder. At runtime. you will be asked to provide values for the variables before the statement can be executed. Page 5 of 13 .

click the parent query in the Queries tree to go back to the original query. Use this new table as you would any other database object. Subqueries The query build allows you to add a sub query to the FROM clause. A sub query can be added by clicking on the Add Subquery toolbar button or from the context menu on the diagramming surface. Choose from the pre-defined list of functions and operators or free text the formula directly. Activating this option opens the Queries tree on the left side of the form and opens a sub query builder control.Query Builder – Overview Formulas Formulas can be applied to columns and calculated fields. Page 6 of 13 . The first thing you will notice is a new table on the diagram surface with all the columns from the sub query. You can nest sub queries and the Where Condition sub query works as it did before. When you are done creating the sub query. You add tables and views and create joins in the same way as you normally use the query builder. .

” “Last 30 days. “Today.” and “Current year. Date Range tags can also be used in the SQL Editor so you can create queries manually if you wish.” The tag you select is added to the where clause of your query and when executed it is substituted with a BETWEEN command using the appropriate date range.” “Last week. you will notice a new tab named Date Range. The Date Range tab allows you to select a plain text tag such as.Query Builder – Overview Distinct Values Date Ranges When you open the Where Condition dialog for a column that has a Date data type. Page 7 of 13 .

Query Builder – Overview Lookup Tables A lookup table is an associative array which in the context of a database application creates a new table with defined relationships to the distinct values of the original table. Page 8 of 13 .

Once a table or view from a different database has been added to the query builder. Page 9 of 13 . a watermark is shown indicating you are working with a heterogeneous query. With a query builder open. You should not uninstall this database if you intend to create heterogeneous queries. you can change connections and still add tables from a different database. Note: The Query Builder uses the Microsoft Access database installed with Toad as a staging area for the query. The query engine uses an ODBC connection to connect to the database where the table resides even when connected via one of the .Net native providers.Query Builder – Overview Heterogeneous Queries You can use the query builder to add tables and views from multiple databases and retrieve a combined result set.

In addition. You cannot create a heterogeneous query from a DB2 native client connection.Query Builder – Overview Query Limitations Executing a heterogeneous query may take longer than a query run against a single database. result sets from each database are retrieved and combined increasing the length of time to get a result set. WHERE. GROUP BY. The statement can contain calculated columns. Simply type or paste a SELECT statement into the editor on the Query tab and click on the Visualize SQL statement button to draw a diagram of the objects and relations in the SQL. Result sets from a heterogeneous query cannot be edited. You must first establish an ODBC connection to the DB2 database and then create the query. ODBC data retrieval is naturally slowing than using a native database client connection. Page 10 of 13 . HAVING. The only join types that work with heterogeneous queries are CROSS JOIN and INNER JOIN. You cannot create a heterogeneous query between two or more Excel connections. ORDER BY clauses. Edits made on the Diagram tab will cause the Query tab to be updated thus overwriting the entered SQL. Reverse Engineering The Query Builder allows you to enter a SELECT statement in the Query tab and reverse engineer it into a visual representation on the Diagram tab. Heterogeneous queries between Microsoft Access and Microsoft Excel are not supported. All access points to change the join type have been disabled. Sub queries do not work with heterogeneous queries so all access points to add sub queries have been disabled. and sub SELECT statements.

the Global Clause objects are used to contain the logic of the clause. The Global Clause can be edited by double clicking on the object or clicking the Global Where or Global Having buttons on the toolbar.Query Builder – Overview Since a WHERE or HAVING clause can be entered that the Query Builder can not visually represent. Errors in the SELECT statement will be flagged in the editor and added to the Output window. Page 11 of 13 . Reverse engineering a SELECT statement that contains a WHERE or HAVING clause produces a Global Where Clause or Global Having Clause object in the Diagram.

Page 12 of 13 . only the first statement is used.Query Builder – Overview Reverse Engineering Limitations The Query Builder only supports one statement at a time. MINUS and EXCLUDE joins are not supported. You cannot reverse engineer heterogeneous queries. you must use ANSI SQL for the query. If you make any changes to the statement on the diagram tab. If you are connected via ODBC. If you add multiple statements to the Query tab. UNION. the other statements are lost. You can build the statement in the Query Builder and send it to the editor to add one of these join types.

com.com Quest Software. delivers innovative products that help organizations get more performance and productivity from their applications.quest..754.8000 (United States and Canada) info@quest. World Headquarters 5 Polaris Way Aliso Viejo. and lowers the operating cost of managing applications. Inc.com Please refer to our Web site for regional and international office information.pdf Page 13 of 13 . Quest Software can be found in offices around the globe and at www. you can do the following: Quickly find thousands of solutions (Knowledgebase articles/documents). Inc. and policy and procedures. Windows infrastructure and virtual environments. Quest’s Foglight® application management solution unifies IT services with end users and the business. Download patches and upgrades. View the Global Support Guide for a detailed explanation of support programs.Query Builder – Overview ABOUT QUEST SOFTWARE. online services. databases.quest. Quest Support provides around the clock coverage with SupportLink. a leading enterprise systems management vendor. resolves problems faster to reduce downtime. INC. Through a deep expertise in IT operations and a continued focus on what works best. and check its status.com From SupportLink. The guide is available at: http://support. Quest Software.000 customers worldwide meet higher expectations for enterprise IT. CA 92656 USA Web site: www. Contacting Quest Software Phone: Email: Mail: 949. Seek help from a Support engineer.quest.quest.com/pdfs/Global Support Guide. contact information. our web self-service. Visit SupportLink at http://support. Quest helps more than 90. Log and update your case. Contacting Quest Support Quest Support is available to customers who have a trial version of a Quest product or who have purchased a commercial version and have a valid maintenance contract.