Quest Software 3.1 Toad for Data Analysts User Guide
Reklama
Reklama
Toad
®
for Data Analysts 3.1
User Guide
© 2012 Quest Software, Inc.
ALL RIGHTS RESERVED.
This guide contains proprietary information protected by copyright. The software described in this guide is furnished under a software license or nondisclosure agreement. This software may be used or copied only in accordance with the terms of the applicable agreement. No part of this guide may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying and recording for any purpose other than the purchaser’s personal use without the written permission of Quest Software, Inc.
The information in this document is provided in connection with Quest products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Quest products. EXCEPT AS
SET FORTH IN QUEST'S TERMS AND CONDITIONS AS SPECIFIED IN THE LICENSE
AGREEMENT FOR THIS PRODUCT, QUEST ASSUMES NO LIABILITY
WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY
WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL QUEST BE LIABLE FOR
ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL
DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF
PROFITS, BUSINESS INTERRUPTION OR LOSS OF INFORMATION) ARISING OUT OF
THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF QUEST HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Quest makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Quest does not make any commitment to update the information contained in this document.
If you have any questions regarding your potential use of this material, contact:
Quest Software World Headquarters
LEGAL Dept
5 Polaris Way
Aliso Viejo, CA 92656 www.quest.com
email: [email protected]
Refer to our web site for regional and international office information.
Trademarks
Quest, Quest Software, the Quest Software logo, Benchmark Factory, Toad, T.O.A.D.,
Toad World, and vToad are trademarks and registered trademarks of Quest Software, Inc in the United States of America and other countries. For a complete list of Quest
Software’s trademarks, please see http://www.quest.com/legal/trademark-information.aspx
.
Other trademarks and registered trademarks used in this guide are property of their respective owners.
Toad for Data Analysts 3.1
User Guide
March 03, 2012
Table of Contents
Introduction
Understand Toad's Workflow
Connect
Create ODBC Connections
Understand Toad Connections
Understand
Determine the Best Method to Locate Objects
Object Explorer
Filter Databases and Objects
Tutorial: Understand a Table Using the Database Explorer
Search for Objects
Tutorial: Create a Database Diagram to Use as a Query Template
Browse Data in Related Tables
Query
Tutorial: Visually Build a Query
Create Cross-Connection Queries
Considerations and Limitations of Cross-Connection Queries
Reverse Engineer Queries
Considerations and Limitations in the Query Builder
Tutorial: Build a Subquery
About Editing SQL
Editor Shortcut Keys
View Result Sets
11
13
16
17
10
10
10
7
7
8
6
6
19
21
21
23
26
30
33
35
38
Toad for Data Analysts User Guide
Table of Contents
Compare Differences in Data
Export Data with One Click Export
Share Excel Linked Queries
Report
Tutorial: Create a Toad Data Report
Step 1: Run the Toad Data Report Wizard
Step 3: Use Styles to Format the Report Appearance
Step 4: Update Bands and Add Controls
Manage Reports
Publish and Share Reports
Automate
Scenario: Automate a Query and Email the Report
Automate Tasks
Use Database Automation Activities
Use File Automation Activities
Use System Automation Activities
Use Variables in Automation
Generate Reports per Product (Use the Loop Dataset Activity)
73
79
83
64
64
66
69
40
40
43
45
62
45
51
4
Toad for Data Analysts User Guide
Table of Contents
Find Unbatched Transactions (Use the Row Count Field and If..Condition..
Execute Automation Scripts
Appendix: Contact Quest
Contact Quest Support
Contact Quest Software
About Quest Software
Index
91
92
93
90
91
91
5
1
Introduction
Understand Toad's Workflow
Most reporting projects have a general flow throughout their lifecycle that requires you to understand your data sources, create queries, generate reports based on query results, and automate scripts for repetitive tasks.
l
Understand—Successful queries begin with a clear understanding of the data source to which you connect. If you understand the data and the objects, as well as their relationships to one another, you can build informed queries that are effective and more optimized than you could without this understanding.
l
Query—Queries are the most important, and often the most time-consuming, aspect of your project. Once you have a clear understanding of the data source, you can begin to create your query.
l
Report—Data retrieved from a query frequently needs to be shared with colleagues or management in the form of a report, such as a pivot grid or chart.
l
Automate—Queries and reports usually need to run on a daily, weekly, or monthly basis. With Automation, you can create a workflow that includes connecting to data sources, importing/exporting data, executing scripts, running queries, and building and distributing reports on a scheduled basis.
2
Connect
Create ODBC Connections
The purpose of the ODBC provider is to offer basic connection and querying capabilities to any database that supports an ODBC 3.0 or later driver. For a list of databases tested with the
ODBC provider, see the Release Notes. This form of connectivity allows connections to databases such as Netezza, IBM iSeries, Ingres, and Vertica. Because this form of connectivity is generic, it is not full-featured and may not be as robust as the fully exploited providers for databases that use a native provider.
To create an ODBC connection
1. Click on the toolbar (ALT+F+N+O).
2. Select ODBC from the Group list box.
3. Click
4. Click Add.
in the Data Source Name field.
5. Select an ODBC driver from the list, and click Finish.
Note: If creating an Oracle ODBC connection, select the ODBC driver provided by
Oracle. The Microsoft ODBC for Oracle driver has less functionality than the driver provided by Oracle.
6. Specify the configuration properties required for the database in the windows configuration dialog.
Notes: l
If you have an Oracle database with Unicode data, make sure to select Force
SQL_WCHAR Support on the Workarounds tab of the windows Oracle ODBC
Configuration dialog. If you do not, you will not be able to see the data.
l
If creating a MySQL ODBC connection to use in a cross-connection query, you must specify a database in the windows MySQL ODBC Configuration dialog. See Troubleshoot MySQL Issues for more information.
7. Specify the connection properties in the Create New Connection dialog. Review the following for additional information:
Use data source name
Data source
Select to display the Data source names.
Deselect to display the driver names.
Select the driver or data source name you added in the previous
Toad for Data Analysts User Guide
Connect name
User
Password
Database steps.
Enter the user name to use when connecting.
Enter the password to use when connecting.
Tip: After connecting, you can set a master password to further secure your connection in Tools | Options| Environment |
Security.
Specify the location of the database schema. Click to create a temporary connection and display available schemas in the dropdown list.
Information
Data
Source
Name
Driver
Category
Displays the selected driver or data source name.
Displays the ODBC driver associated with the data source.
Select or create a category if you want to color code Editor tabs for a specific connection. This can help differentiate between development and production databases. You can also set an option to color code the Object Explorer pane and object editor windows (Create, Alter, Drop, etc.).
Click here to view a video of this feature.
8. Click Connect to save the connection and immediately connect to the database.
or
Click Save to save the connection without connecting to the database.
Tip: Connections are stored in the connections.xml file and can be found by clicking the
Application Data Directory link in Help | About.
Click here to view a video about creating connections in Toad for Data Analysts
Understand Toad Connections
In Toad, a connection represents one or more actual connections to the database. Toad creates an initial database connection for general usage. It also creates a separate database connection for each Editor (the first time you execute a statement) and a separate database connection for each Data tab in the Database Explorer (the first time you select the tab and data is queried).
The database connection for each Editor and Data tab remain open until you close the associated window; however, the connections remain in an inactive state if a statement is not currently executing.
8
Toad for Data Analysts User Guide
Connect
Tips: l
To view the number of actual database connections that exist for a Toad connection and how many of those database connections are active, place the cursor over the connection in the Navigation Manager or the Connection toolbar (illustrated in the following example).
9 l
You can view the progress of statements executing in the background in a progress bar located on the lower right side of the status bar. To cancel a script's execution, click the progress bar to display the Background Processes window. It is recommended to cancel only your own processes, as terminating Toad activities may lead to unexpected behavior.
Share Database Connections
Editors and Data tabs can share the same database connection when the connection is inactive if you clear the Use specific connection for each open editor checkbox in Tools
| Options | Editor | General. Any new executions or windows attempt to use this connection first. For example; if you share a database connection, you can execute a query in the Editor, execute another query in a new Editor, and then select the Data tab from the same connection. If the connection is in use and you attempt to execute it, one of the following occurs: l
(DB2 and Oracle only) If your database supports executing multiple queries simultaneously on a shared connection, the query is placed in a queue and executes as soon as the current operation completes.
l
If your database does not support executing multiple queries on a shared connection, a dialog prompts you to either permanently associate the window with a new database connection, cancel the previous operation, or add the query to a queue until the current operation completes, and the execute it. If you place multiple queries in the queue, each one executes in the order that it was added to the queue.
Note: Although you can share a database connection, any commits apply to the selected window only.
Understand
Determine the Best Method to Locate Objects
Toad offers a number of features to assist you in locating objects. The following table provides guidelines based on typical use cases:
If you know the....
Column name, but do not know the table name
String of DDL for an object
Dependency for an object
Use this...
Use Object Search
Criteria for excluding objects
Uses and Used By tabs in the Database
Explorer, ,and then drill-down to the object from there
Filter feature in the Object Explorer
Object Explorer
You can view database objects for the current connection with the Object Explorer. This feature is useful for dragging and dropping database objects into an open Editor, Query
Builder, or other document window. Right-click the objects in the Object Explorer to access additional features such as multiple tasks and actions.
To open the Object Explorer
1. Click on the View toolbar.
2. Review the following for additional information:
Schema (first field)
Object Filter
(second field)
Select the schema you want to view. You can filter the list of
schemas that display. See "Filter Databases and Objects"
(page 11) for more information.
You can quickly set a filter in this field. To do so, enter a name or partial name of an object and press ENTER. Any advanced object filters you set display in this field.
You can also perform advanced filtering based on case
sensitivity, statistics, or other options. See "Filter Databases
3
Toad for Data Analysts User Guide
Understand
and Objects" (page 11) for more information.
Tip: You can enable an option to filter using regular expressions in Tools | Options | Explorer | General.
Note: For tables and views, the columns, data types, and comments display at the bottom of this window.
Tips: l
To navigate to a previously selected object, click . You can also click to the next selected object.
to move l
To locate objects including procedures, functions, views, variable names and
comments in an object's source code, use Object Search. See "Search for Objects"
(page 16) for more information.
l
To use a different method to select objects such as tabs, drop-downs, or a tree view, click .
l
To generate reports, export data, create SQL statements, version control objects, or send objects to the Project Manager, SQL Modeler, or Master Detail windows, rightclick the objects and select an option.
l
To open the Background Processes window and cancel a query, click the progress bar at the bottom of the window.
Filter Databases and Objects
Filters can reduce the number of database and/or objects you have to work with and reduce the amount of time required to query large databases. You can set the following types of filters: l
Quick filter—Applies to the current schema, or objects in the current schema only.
Any unnamed filter you set is in effect the next time you open Toad l
Unnamed filter—Applies to the current schema, or objects in the current schema only.
Any unnamed filter you set is in effect the next time you open Toad.
l
Named filter—Applies to any database connection for the current database provider.
Any named filter you set is in effect the next time you open Toad.
Note: If you rename a table that has a filter defined, it results in an orphaned filter.
Orphaned filters are automatically removed unless you used a tool other than Toad to remove them.
A filter is associated with a specific list of objects from a specific database. Consider the following guidelines when setting filters:
11
Toad for Data Analysts User Guide
Understand
12 l
A filter defined for a set of objects such as tables on one specific database connection does not apply to a list of objects for another database connection.
l
A filter defined for a list of tables on one schema in the database does not apply to the list of tables for a different schema on the same database.
l
A filter set for a specific schema or object is applied when altering objects, using the
SQL Editor, Master Detail Browser, etc., for that schema or object.
Tip: To apply any filters you set to the code completion list in the editor, select the
Apply explorer filters checkbox in Tools | Options | Editor | Code Completion.
To set a quick filter
» Enter text to use for filtering in the field below the database/schema name in the
Object Explorer:
To set a named filter
1. Click beside the database or object field in the Object Explorer.
2. Define criteria for the filter in the Properties tab.
3. Select the SQL tab and select the Enable custom SQL checkbox to create a custom filter based on criteria you specify.
4. Select the Preview tab to view a list of databases or objects that meet your filter criteria before applying the actual filter.
5. Enter a name for the filter if you want to use the filter for other database connections and click .
Icon Description
A filter has not been set so all databases/objects display.
A filter has been set.
Toad for Data Analysts User Guide
Understand
6. If you set a named filter, you can click the arrow beside the icon to apply or remove the filter:
13
Tips: l
To export a named filter or any filters associated with the current connection, click the arrow beside the icon and select Export Filters.
l
To import the filters, select File | Open from the menu.
Click in the Explorer toolbar to clear all database, object, and data filters.
Tutorial: Understand a Table Using the
Database Explorer
Click here to view a video of this feature.
Scenario
You need to build a query listing customers and want to know more about the table before writing the query.
Note: This exercise uses the Toad Sample Database. This connection does not have the relationship and script tabs. The tabs available can differ depending on the type of connection.
Note: This topic focuses on information that may be unfamiliar to you. It does not include all step and field descriptions.
To understand a table using the Database Explorer
1. Connect to the Toad Sample (Access) database in the Navigation Manager.
2. Right-click the CONTACT table and select View Details.
Toad for Data Analysts User Guide
Understand
3. View information for the following: a. Click the Indexes tab and view the index information.
b. Click the Primary Keys and Foreign Keys tabs to view relationships.
4. Click the Data tab.
5. Place the cursor over the LAST_NAME column, click , and select Acton.
14
The only row that now displays is the one with Acton as the last name.
6. Click to the right of the LAST_NAME column again and select All to clear the filter.
7. Click the CONTACT_ID column to sort the rows in ascending or descending order.
8. Click in the top left of the Data tab.
9. Create the following filter in the Where Clause tab:
CONTACT_ID > 2000
The filter string displays at the bottom on the grid. Click to remove the filter.
Toad for Data Analysts User Guide
Understand
10. Select a row of data in the grid. Notice that the row number changes in the bottom right of the status bar:
15
11. Under the SEX column, right-click the area below the last row in the grid that says
"Right-click to add column totals" and select Count. The total number of rows that have either a M or F value display.
12. Click to the right of the SEX column and select F. The count value updates based on the new filter.
13. Click to the right of the SEX column again and select All to clear the filter.
14. Select the SEX column header and drag it the area above the columns that says "Drag a column header here to group by that column":
You can expand each group to view the row data.
15. Switch the default view: a. Right-click within a group or row on the grid and select Show | Card View.
b. Scroll through some records.
c. Click Customize in the Card View window.
d. Click Filter beside the ADDRESS_ID column and select 100. Notice how the card view is filtered, but not the grid view.
e. Close the Card View window.
16. Edit a row: a. Select a row in the FIRST_NAME column and edit the value.
b. Press ENTER to update the row.
Toad for Data Analysts User Guide
Understand
16 c. Go to the BIRTH_DATE column and use the date picker to change the date.
Each data type have an appropriate editor.
Note: If you are using Oracle or a database that does not have auto commit on, you will need to press Commit at the left hand bottom of the window.
17. Update the number of rows in in the data: a. Select Tools | Options | Database | General from the menu.
b. Enter 50 in the Number of rows to initially fetch in data tab.
c. Click OK.
d. Press F5 in the data grid. Notice the bottom right status bar now says "1 of 50
(scroll for more)".
The option you set controls the number of rows fetched in the Data tab.
e. Click the scrollbar and hold down to retrieve more.
f. Right-click the grid and select Read All Rows.
Search for Objects
You can quickly locate an object rather than browsing through a list of objects in the
Database Explorer orObject Explorer. Object Search locates the following: l
Names of objects for a string.
l
Text in objects that include source code, which typically includes procedures, functions, triggers, data types, and views. However, the database provider determines which objects include source code.
l
Variable names and comments in the object's source code.
l
Column names for tables and views.
To search for objects
1. Click on the toolbar (F4).
2. Specify search criteria and click Search.
Note: To append additional search results to the current search, click Append instead.
If you click Search, new results replace the previous search results in the data grid.
Toad for Data Analysts User Guide
Understand
Tips: l
To remove objects from the search results, right-click the objects in the data grid and select Remove Items. This is useful if you want to narrow the list of results to relevant objects.This does not remove the objects from your database.
l
To create a DDL script from the search results, right-click the data grid and select
Create DDL Script. You can then paste the results into the Editor.
l
To perform any actions available for the object, such as creating, altering, dropping, exporting, and generating reports or SQL, right-click the results in the data grid and select an option.
Tutorial: Create a Database Diagram to Use as a
Query Template
Click here to view a video of this feature.
Scenario
Your company creates several daily and weekly reports regarding customer sales. You need to create a Database Diagram that can be used as a template for these queries.
To create a Database Diagram to use as a query template
1. Connect to the Toad Sample (Access) database in the Navigation Manager.
2. Click .
3. Drag the CONTACT table in the Object Explorer to the Diagram pane.
17
Toad for Data Analysts User Guide
Understand
18
4. Right click the Diagram pane and clear Show Dependencies to hide the Referenced
Objects at the bottom of each table/view, as illustrated in the following:
5. Right-click the ORDERS table and select Notes.
6. Enter the following note in the window for other users:
The shipping and billing ADDRESS_ID foreign key relations are not needed in most queries and should be hidden when building a query.
Toad for Data Analysts User Guide
Understand
19
7. Because it is against company policy to display sex and a home phone number in reports, right click on each of these columns in the CONTACT table and select
Hide Column.
Tip: If you have a large number of columns you need to hide, you can right-click a table and select Manage Hidden Columns to quickly select them from a list.
8. Click Add to Project from the wizard bar at the bottom of the window and enter
DBDiagram_Test asthe name for the file. This adds the file to the current project in the Project Manager under a Diagrams folder.
9. Close the Database Diagram window and open the Project Manager window.
10. Expand the Diagrams folder and double-click DBDiagram_Test to reload the file in a new Database Diagram window.
11. To share your project, hidden columns, and notes with colleagues, complete the following: a. Select Tools | Options | Environment | Network Share, and navigate to a shared drive where you want to store the Project Manager file.
b. Select Database | Cache from the open Options window and set the following options:
Object An notation Cache
Share object annotations
Share hidden column settings
Description
Select this checkbox and enter a shared drive location where users can access this file.
Select this checkbox.
c. Provide the location of the Network Share and Object Annotation Cache settings to colleagues who need to use this diagram.
Browse Data in Related Tables
Use the Master Detail Browser to browse data in parent tables and drill-down to data in related child tables. This is useful when you need to analyze or edit data. For example, suppose you need to view a list of all Nick's Flix stores and the inventory of comedy movies at each store. Using the Master Detail Browser, you specify the table that contains the list of stores as the parent table and specify the table that contains comedy movies as the child table to quickly locate comedies and analyze the inventory.
To browse tables using the Master Detail Browser
1. Select Tools | Master Detail Browser (ALT+T+A).
2. Drag one or more tables from the Object Explorer, Object Search, or Project Manager
Toad for Data Analysts User Guide
Understand
20 window to the Diagram pane at the top of the Master Detail Browser. Press
CTRL+click to select multiple tables at once.
Notes: l
A line between tables indicates any existing relationships between the selected tables.
l
At least one parent table (table without any join arrows pointing to it) must be added to the window or an error message displays when returning results.
3. Join Columns.
4. Select the checkbox beside each column you want to include.
Note: Any columns included in a join are automatically included in the results.
5. Click (F9) to retrieve data for the parent table initially. To view data in a child table, click + to the left of each row.
or
Click to retrieve data in the parent and child tables. If there is more than one child table, a tab displays for each child table.
6. From the data grid, you can: l
Edit the data and commit your changes to the database.
l
Right-click the data grid and select Send To | option to add the data to a report, chart, or pivot grid.
Tips: l
Click to align tables and snap them to the grid.
l
Select the parent table from the drop-down list in the toolbar to view data for a parent table if there are multiple parent tables.
l
Click X on the table you want to remove in the Diagram pane to remove a table and any conditions (e.g., join, where clause) associated with the table.
4
Query
Tutorial: Visually Build a Query
The Query Builder enables you to create a query without writing or editing SQL statements.
Even if you are familiar with SQL, the graphical interface makes it easier to create relationships and visualize the query.
Note: This procedure does not cover all of the possible steps of visually building a query. It only covers the steps required to build a query for the scenario.
Scenario
Your company wants to improve its global sales, starting with countries where it has a customer base but generally low sales. You need to create a query that identifies countries with less than
$500,000 in sales for each of the last four fiscal years.
Note: This scenario uses the SH (Sales History) sample schema that comes with Oracle 10g so you can follow the procedure.
To visually build a query based on this scenario
1. Connect to the database and click Query Builder.
2. Select the SH schema in the Object Explorer.
3. Drag the following tables from the Object Explorer to the Diagram pane: TIMES,
SALES, CUSTOMERS, and COUNTRIES.
Tips: l
Select Query Builder | Arrange Tables (ALT+Q+A) to have Toad arrange the tables in the Diagram pane.
l
You can press CTRL and select a table, and then drag the table into the Editor pane. Click the list to create statements.
l
You can also press CTRL and select all of the tables in the Object
Explorer, and then drag them into the Diagram pane. Toad automatically arranges the tables.
4. Add the following columns to the query by clicking each column:
Table
COUNTRIES
Column
COUNTRY_NAME
Toad for Data Analysts User Guide
Query
22
Table
TIMES
SALES
Column
FISCAL_YEAR
AMOUNT_SOLD
Tips: l
To view details for a table in the Diagram, click selected, details for the last selected table display.
(F4). If a table is not l
To remove a column from the query, click or drag column off grid.
5. Complete the following steps to group the data and sum the sales: a. Select the Group By field in the COUNTRY_NAME column, and then click +. The Group By field is in the Criteria pane, which is below the
Diagram pane.
b. Select the Group By field in the FISCAL_YEAR column, and then click +.
c. Select the Aggregate Function field in the AMOUNT_SOLD column and select Sum. This sums all of the sales per fiscal year per country.
Note: If you select a group by clause or aggregate function for a column, the rest of the columns in the query must also have a group by clause or aggregate function.
6. Complete the following steps to select the fiscal year range: a. Select the Where Condition field in the FISCAL_YEAR column and click .
The Where Condition window displays.
b. On the Form tab, select BETWEEN in the Operators field.
c. Select 1998 in the first Constant field.
d. Select 2001 in the second Constant field and click OK.
Note: The SH schema does not have current data. The 1998-2001 years provide the best data for the purposes of this scenario.
7. Complete the following steps to select countries with less than $500,000 in sales: a. Select the Having Condition field in the AMOUNT_SOLD column and click
. The Having Condition window displays.
b. On the Form tab, select < in the Operators field.
c. Select Sum in the Aggregate field.
d. Enter 500000 in the Constant field and click OK.
8. Select Ascending in the Sort field of the COUNTRY_NAME and FISCAL_
YEAR columns.
Toad for Data Analysts User Guide
Query
9. Click .
The query results display in the Results tab. See "View Result Sets" (page 38) for more information.
23
10. To save the query, right-click the Query Builder tab and select Save File.
You can save a query and any results sets in a Toad editor file (.tef). This file format is useful for building scripts that have large result sets that you do not want to continue executing or for saving results when you have not finished building a script.
Create Cross-Connection Queries
Use the Cross-Connection Query Builder or the Cross-Connection Editor to create a query that combines data from multiple, dissimilar databases. For example, you can create a query that joins managers from a SQL Server database to their employees in an Oracle database.
(This is also often called a heterogeneous or cross-database query.) Toad uses an enhanced query engine to implement advanced execution processes that are specially designed to improve the performance of cross-connection queries.
Before creating a cross-connection query using an Oracle, Teradata or MySQL ODBC connection, or if using the Base edition, please see the special considerations listed at the end of this topic.
Notes: The enhanced and fully-optimized version of cross-connection query is available only in the Professional and Premium editions of Toad for Data Analysts.
Toad for Data Analysts User Guide
Query
24
To build a cross-connection query visually
1. Select Build Query | Cross-Connection Query Builder.
Note: A blue banner along the right side of the Diagram pane indicates that you are in Cross-Connection Query mode.
2. Drag tables and views from the Object Explorer to the Diagram pane.
3. Complete the query in the same manner as you would a non-cross-connection query, but note the following exceptions.
Object Explorer Feature
Options
Filters
In Cross-Connection Query Mode...
Connection Treelist is the only view option available.
In this option, connections, databases, tables, and views are displayed in a treelist in the Object Explorer window.
Filters are especially useful in cross-connection queries to reduce the number of objects displayed in the treelist in the Object Explorer window.
Note: Review the "Considerations and Limitations of Cross-Connection Queries" section below.
To compose a cross-connection query in the editor
1. Select Editor | Cross-Connection SQL Editor.
Note: A blue banner along the right side of the Editor pane indicates that you are in
Cross-Connection Query mode.
2. Compose the SQL statement in the same manner as you would a non-cross-connection query, but note the following exceptions.
SQL Editor Task
Naming tables and views
In Cross-Connection Query Mode...
To reference a table or view, you must use a crossconnection fully-qualified name. The format for a crossconnection fully-qualified name depends on the database. The following is an example using the SQL
Server format:
<database connection string>.<database>.<schema>.<table>
'sqlserverconn'.database.dbo.table
Note: For the database connection string, use the connection string displayed in the Navigation Manager window for each connection (or in the Name field in
Connection Properties).
Toad for Data Analysts User Guide
Query
25
SQL Editor Task
Using alias names
Using code completion
In Cross-Connection Query Mode...
Tip: Copy and paste a SQL statement from a single connection editor to a cross-connection editor and Toad automatically changes the syntax of the statement to include the cross-connection fully-qualified names.
You must use alias names for tables and columns in a cross-connection query.
In Cross-Connection Query mode, the scope of available options in code completion expands to include the databases, tables, and views for all the open database connections.
Tip: To expand/collapse a database node in the code completion list, use CTRL+left arrow and CTRL+right arrow.
Tips: l
In a cross-connection code completion list, the selected database displays a descriptive tooltip containing database and connection information.
l
To learn how to optimize cross-connection queries, see Optimize Cross-
Connection Queries.
Considerations and Limitations of Cross-Connection
Queries
Review the following considerations and limitations before creating a cross-connection query.
Consideration/Limitation
Toad Access database
Performance concerns
Description
In the Base edition of Toad for Data Analysts, the
Query Builder uses the Access database installed with
Toad as a staging area for the query. Do not uninstall this database if you need to create cross-connection queries.
A cross-connection query may take longer to execute than a query against a single database because result sets from each database are retrieved and combined to generate a single result set.
In the Professional edition of Toad for Data Analysts, the enhanced execution engine utilizes several optimizing techniques to improve the performance of cross-connection queries.
Toad for Data Analysts User Guide
Query
26
Consideration/Limitation
ODBC driver support
Using an Oracle connection in a cross-connection query
Oracle Direct Connection
Using a Teradata connection in a cross-connection query
Using a Teradata connection in a cross-connection query in the Base edition of Toad
Using a MySQL ODBC connection in a crossconnection query
Result sets
Oracle Long Data Type
Description
An ODBC driver can be selected for a single connection through each connection's Properties dialog or globally through Tools | Options | Database.
To use an Oracle connection in a cross-connection query, you must install an Oracle ODBC driver.
Note: The Oracle Full Install client includes an ODBC driver. However, if you are using the Oracle Instant client (which may not include an ODBC driver), you may need to install an Oracle ODBC driver.
You cannot use an Oracle Direct Connection in a crossconnection query.
To use a Teradata connection in a cross-connection query, you must install a Teradata ODBC driver.
In the Base edition of Toad, to use a Teradata connection in a cross-connection query, you must create and use a Teradata ODBC connection (instead of the native connection).
To use a MySQL ODBC connection in a crossconnection query, you must specify a database for the connection.
You cannot edit result sets.
Cross-connection query does not support Oracle long data types or Oracle LOBs.
Reverse Engineer Queries
One way to build a query is to begin adding columns and creating joins in the Query
Builder, and then send the query to the editor to add more complex functionality, such as a
UNION join. You can also send a query from the editor to the Query Builder. For example, you inherited a large query when an employee left and you need to edit it to resolve an issue.
After looking at the query in the editor for some time, you still cannot decipher it. So, you right-click the statement and select Send to Query Builder. Now that you can visually see how the tables are referenced, you can identify and resolve the issue.
Toad for Data Analysts User Guide
Query
Considerations and Limitations in the Query Builder
Consider the following when reverse engineering a query using the Query Builder:
General
Single statement support
Quote identifiers
ODBC support
Excel support
Non-ANSI joins
(Oracle only)
Where Condition
Where condition does not display in the Criteria grid after sending it to the
Query Builder from the Editor
Where condition created in the
Criteria grid of the
Diagram tab
Description
The Query Builder only supports one statement at a time. If you add multiple statements to the Query tab, only the first statement is used. If you make any changes to the statement on the Diagram tab, the other statements are lost.
If you selected the Quote Identifiers checkbox in Tools |
Options | Database | General and generate a query from the
Query Builder in SQL Server, the query cannot be reverse engineered.
You must use ANSI SQL for the query.
Copying a generated query and attempting to reverse engineer that query results in an error. This issue occurs because the parser defaults to Oracle syntax, which does not understand quotation marks for fully qualified object names.
To avoid this issue, clear the Use fully qualified object
names and Use fully qualified column names checkboxes in
Tools | Options | Database | Query Builder or manually edit the query.
When sending a query from the Editor to the Query Builder,
Toad automatically uses ANSI joins. If you use Where clause joins, click to disable ANSI joins. This converts the statement to the correct join.
Description
If you send a query that contains a Where condition from the editor to the Query Builder, it displays in a Global Where clause bubble on the Diagram pane instead of in the Where
Condition field in the Criteria grid.
You can double-click the Global Where Clause bubble in the Diagram pane or can click to edit it.
You can also use the Where condition fields in the Criteria grid to add new Where conditions. Although they display in the grid, they are added to the Global Where clause in the
Query tab.
If you define a Where condition in the Criteria grid and edit any part of the query in the Query tab, the Where condition is removed from the Criteria grid and placed in a Global
Where Clause bubble.
27
Toad for Data Analysts User Guide
Query disappears
Having Condition
Having condition does not display in the Criteria grid after sending it to the
Query Builder from the Editor
Having condition created in the
Criteria grid of the
Diagram tab disappears
You can double-click the Global Where Clause bubble in the Diagram pane or can click to edit it.
Description
If you send a query that contains a Having condition from the editor to the Query Builder, it displays in a Global
Having clause bubble on the Diagram pane instead of in the
Having Condition field in the Criteria grid.
You can double-click the Global Having Clause bubble in the Diagram pane or can click to edit it.
You can also use the Having condition fields in the Criteria grid to add new Having conditions. Although they display in the grid, they are added to the Global Where clause in the
Query tab.
If you define a Having condition in the Criteria grid and edit any part of the query in the Query tab, the Having condition is removed from the Criteria grid and placed in a Global
Having Clause bubble.
You can double-click the Global Having Clause bubble in the Diagram pane or can click to edit it.
Description Query Builder
Diagram Tab
Comments and code regions removed after making changes in the Diagram tab
Same column cannot be used in the criteria grid
Execute with different query in the
Diagram and Query tabs
Save with different query in the Diagram and Query tabs
When reverse engineering a statement from the editor or the
Query tab and switching to the Diagram tab, if the statement contains a block comment or code region and you make a change in the Diagram tab, the comment or code region is removed from the statement.
You cannot use the same column more than once in the criteria grid. Even if you create a separate alias for the second use of the column, that column is created as a calculated field
If the query in the Diagram tab is different than the query in the Query tab, executing the query executes the SQL in the
Query tab instead of the Diagram.
The Query Builder saves both the statement and diagram in the same file. The contents of the statement and diagram can be different without losing changes.
28
Toad for Data Analysts User Guide
Query
29
To reverse engineer a query
1. Right-click a statement in the Editor, and select Send to Query Builder.See "About
Editing SQL" (page 33) for more information.
or
Click in the Query Builder to send a statement to the Editor. Skip the remaining
steps and continue to edit the query. See "About Editing SQL" (page 33) for more information.
Troubleshooting: If the query cannot be modeled in the Diagram tab, a message displays and the statement opens in the Query tab. This usually occurs because the graphical diagram cannot support some functionality in the statement. You can view an explanation for this in the Output window or by hovering over the syntax with a red underline ( ) in the Query tab. To continue, correct the error and click apply the change and open the Diagram tab.
to
2. Continue to build your query visually using the diagram.
3. Select the Query tab and make any additional edits. Indicators for an edited statement are as follows:
Inserted lines
Modified or removed lines
Modified characters
Use the toolbar in the lower-right corner of the Query tab to modify the color used for each indicator.
Caution: If you manually enter or update the statement in the Query tab, you must click to model the query in the Diagram tab. If you do not do this and make additional changes in the Diagram tab, any changes you made in the Query tab are lost.
4. Click to execute the query.
Tip: If you have multiple statements in the Editor and you want to send only one to the
Query Builder, highlight the statement, then right-click it and select Send to Query Builder.
Create Cross-Connection Queries (page 23)
Toad for Data Analysts User Guide
Query
Tutorial: Build a Subquery
Scenario
Your database of customer information includes detailed information for each contact you have within a customer. You need a report that lists all of your customers that have a contact that resides in (or covers) a specific region.
To build a subquery
1. Connect to the Toad Sample (Access) database in the Navigation Manager.
2. Click .
3. Drag the CUSTOMER table to the Diagram pane.
4. Click these column names in the CUSTOMER table to add the columns to the query: l
CUSTOMER_ID l
CUSTOMER_NAME
5. To add a subquery: a. Select the Where field in the CUSTOMER_ID column and click . The
Where Condition editor displays.
30 b. Select the IN operator from the list and click Subquery. A child Query Builder
Toad for Data Analysts User Guide
Query window displays for you to use to build the subquery.
l
The child (subquery) Query Builder window includes a Diagram pane, a Criteria pane, and a Queries pane for navigating back and forth between subqueries and the main query.
31 c. Drag the following tables to the Diagram pane and select the following columns:
Select this table...
ADDRESS
CONTACT
Select this column...
REGION_ID
CUSTOMER_ID d. Select the Where field in the REGION_ID column and click . In the Where
Condition editor, select the equal to (=) comparison operator, select Constant, and select a value of 1.
e. Deselect the checkbox in the Visible field in the REGION_ID column. This will remove the REGION_ID column from the result set.
Your subquery window should look something like this:
Toad for Data Analysts User Guide
Query
32 f. Click to execute the subquery. Select the Results tab to review the result set for the subquery.
6. Click the Query node in the Queries pane to return to the main query window. A callout in the main query Diagram pane indicates that the statement contains a subquery and also shows the type of subquery and which column it is on.
7. Click
To use the Lookup Table to execute the main query.
Use the lookup table to add a description to ID values to aid in selecting from ID columns when building a query or subquery.
1. Click the subquery node in the Queries pane to return to the subquery.
2. In the ADDRESS table, right-click REGION_ID and select Find Lookup Table.
3. Follow the instructions in the Lookup Table dialog to specify the ID Column and the
Description Column.
Toad for Data Analysts User Guide
Query
4. After completing and closing the Lookup Table dialog, again select the Where field in the REGION_ID column and click . Open the drop-down list to the right of
Constant. Notice that a description for each region now displays.
33
About Editing SQL
The editor combines a powerful SQL and procedure editor into a single interface.
Notes: l
See "Editor Shortcut Keys" (page 35) for more information about keyboard shortcuts
used in the Editor.
l
Toad has implemented a large script mode to improve performance when opening files larger than 2 MB. By default, when you open a large file, some features such as word wrap, syntax highlighting, and the Code Navigator are disabled in the Editor. When a large script loads, a message indicates that you are in large script mode in the right margin of the Editor. You can cancel large script mode by clearing the option in
Tools | Options | Editor | General.
To edit SQL
1. Click on the toolbar (ALT+T+E).
Note: You can query the worksheet from the Editor by entering a dollar sign ($) followed by a cell range to limit the results similar to the following statement:
Select * from (MyWorksheet$A1:C10)
You can also query the entire worksheet by entering a dollar sign ($) after the worksheet name; however, this returns empty rows and columns in the worksheet.
2. Review the following to help enter SQL: l
Code completion l
Navigate code
Toad for Data Analysts User Guide
Query
34 l
Code regions l
Code snippets l
SQL recall l
Add/remove application code l
Object lookup (Describe) l
Macros to record keystrokes
3. Click to format the code. See Format SQL for more information.
4. Select the block of code in the Editor, and click to validate the syntax.
Note:Toad undoes any changes to the object and data in the database after executing the script (notice that the Result Sets tab is empty). To modify the object and data, you need to execute the script.
5. Click to execute SQL on the current server or multiple servers at one time.
6. Select the block of code in the Editor and click to create a stored procedure.
Stored Procedure creation dialog automatically recognizes procedure body and declared parameters.
Tips: l
Toad automatically saves a backup copy of any modified editor file in the
Application Data Directory to avoid losing your work. When you restart Toad after an unexpected close, Toad checks the timestamp on the backup file against the original file, and opens the file that has the latest timestamp. The document recovery option is in Tools | Options | Environment | General. See General Environment Options for more information.
l
You can save the current connection, SQL script, executed results, filters, and group execute connections/results (if enabled) in a Toad editor file (.tef). This file format is useful for building scripts that have large result sets that you do not want to continue executing or for saving results when you have not finished building a script.
l
In the Editor toolbar, the execute SQL buttons are grouped under . The button will retain the function of the last execute action for the active Editor window. If you switch to another Editor window, the button will change to reflect the last action for that window.
l
If you copy and paste a SQL statement from one editor window to another, Toad automatically rewrites the statement to match the syntax of the connection for the second editor window.
Toad for Data Analysts User Guide
Query
35
Configure Editor Options
To...
Set options to display line numbers, line modifications, and general text formatting
Specify options to automatically replace typed text with the correct substitution text
Customize code formatting options including headers and layout characteristics
Click here to view a video of this feature.
Use this Option Page...
Editor | General
Editor | Auto-replace
Editor | Formatter
Editor Shortcut Keys
You can assign individual shortcut keys in Keyboard options. See Keyboard Options for more information. You can also customize Toad to use the shortcut keys of existing applications such as Toad for Oracle, SQL Navigator, or Query Analyzer in the Configuration
Wizard (Tools | Configuration Wizard).
Caution! If you have some global access keys assigned, make sure that Toad shortcut keys do not coincide with them. When using such duplicating shortcut keys in Toad, the third party application commands, assigned globally, will be performed instead of ones assigned by Toad.
The following table describes the default shortcut keys in Toad.
Frequently Used Functions
CTRL+PERIOD
F9
F5
CTRL+MINUS
CTRL+SHIFT+MINUS
CTRL+J
CTRL+M
ALT+PAUSE
Description
Displays the code completion list
Execute all statements as a batch
Execute all statements, in order, one at a time
Comments the selected line
Uncomments the selected line
Collapses all code regions
Expands all code regions
Stops script execution
Toad for Data Analysts User Guide
Query
Bookmark
CTRL+SHIFT+0-9
CTRL+0-9
Case
CTRL+L
CTRL+U
Clipboard
CTRL+C
CTRL+X
CTRL+V
Code Completion
CTRL+PERIOD
ENTER
CTRL+SPACE
CTRL+<right arrow>
CTRL+<left arrow>
Comment
CTRL+MINUS
CTRL+SHIFT+MINUS
Cursor
HOME
CTRL+HOME
END
CTRL+END
Debugger
Description
Sets a numbered bookmark at the selected line
Goes to the numbered bookmark
Description
Converts the selected text to lowercase
Converts the selected text to uppercase
Description
Copies the selected text to the clipboard
Cuts the selected text for pasting in the clipboard
Pastes text from the clipboard
Description
Displays code completion list
Selects an item and close the code completion list
Selects an item without closing the code completion list
Expands a node in the code completion list
Collapses a node in the code completion list
Description
Comments the selected line
Uncomments the selected line
Description
Moves the cursor to the beginning of the line
Moves the cursor to the beginning of the file
Moves the cursor to the end of the line
Moves the cursor to the end of the file
Description
36
Toad for Data Analysts User Guide
Query
SHIFT+F12
F7
SHIFT+F7
F8
F11
F12
CTRL+B
CTRL+W
Delete
BACKSPACE
CTRL+BACKSPACE
CTRL+SHIFT+DELETE
Find and Replace
CTRL+F
F3
SHIFT+F3
CTRL+G
CTRL+I
CTRL+SHIFT+I
Indent
TAB
SHIFT+TAB
Macros
CTRL+SHIFT+R
CTRL+SHIFT+P
Step from cursor
Step into
Step out
Step over
Run to breakpoint
Run to cursor
Set breakpoint
Add watch at cursor
Description
Deletes the selected text (if text is selected); otherwise, deletes the previous character
Deletes text to the beginning of the previous word
Deletes the entire script
Description
Finds text
Finds the next occurrence of text
Finds the previous occurrence of text
Goes to line number
Performs an incremental search
Performs a reverse incremental search
Description
Indents the selected line
Outdents the selected line
Description
Starts/Stops recording a macro
Plays the recorded macro
37
Toad for Data Analysts User Guide
Query
Miscellaneous
F4
F4+SHIFT
F6
CTRL+D
SHIFT+F8
CTRL+á
CTRL+â
<auto-replace token>+SPACE
CTRL+SPACE
<code snippet shortcut name>+CTRL+SPACE
CTRL+DELETE
Description
Invokes objects search
Describes the object next to the cursor
Toggles between the Editor and Data Grid
Sends SQL to Query Builder
Recalls the previous SQL statement
Scrolls up the window.
Scrolls down the window
Automatically replaces a misspelled word, inserts symbols, and expands text.
Note: You can set autoreplace in Tools | Options |
Editor | Autoreplace.
Displays the Code Snippets folder browser
Inserts the code snippet template
Sets the column value for the current cell to Null in the data grid
Insert Code Snippets
View Result Sets
The Result Sets tab displays a data grid for executed SQL statements and scripts that return data.
Troubleshoot Data
l
If you cannot edit data, click the red icon in the lower left corner of the grid, and then click OK on the window that displays. You do not need to edit fields in this window.
l
By default, auto commit is enabled and any row changes you make are automatically submitted to the database. You can disable this option in Tools | Options
| Environment | Grid.
38
Toad for Data Analysts User Guide
Query
Tips for Working with Data
To...
Pin a result set so it is not overwritten by a subsequent query in the Editor or
Query Builder.
Do this...
Click the push pin beside the result set:
Set the value of a cell to null.
Toggle between the Editor and Data
Grid.
Add column or group summary values
Press CTRL+DELETE.
Press F6.
Show or hide columns of data.
Display data in a report, pivot grid, or chart.
Compare differences between two data sets.
Display the data in a grid or card view; grid view is useful for viewing summary information at a glance; card view is useful for viewing information in greater detail.
Apply a summary function to the data
(Sum, Min, Max, Count, Avg).
View a list of all existing values in a column, including the number of times a value is used.
Right-click the data and select Show
| Summary Footer Panel. Then, right-click the Summary Footer Panel below the column you want to add a summary total to and select an option.
If you have grouped columns using the
Grouping panel (Show | Grouping Panel), you can also add a summary total to grouped records.
Right-click a column heading in the data grid and select Chooser.
Right-click the data and select Send To
|<option>.
Right-click the data and select Send To |
Data Diff Viewer.
Right-click a record and select Show | Grid
View or Card View.
Right-click below the column you want to apply the summary function (but above the
Navigation toolbar) and select an option.
Right-click the column and select Show |
Existing Values.
39
Toad for Data Analysts User Guide
Query
Compare Differences in Data
You can compare result sets from the current editor or a different editor in the Database
Explorer's Data tab or the editor's Result Sets without having to save one of the sets to a file.
Notes: l
If you want to synchronize data, use Data Compare instead of the Data Diff Viewer.
l
You cannot modify files in the Diff Viewer at this time.
To compare differences
1. Right-click data in the Editor's result set or Database Explorer's Data tab and select
Compare To | Set_number.
You can also save a result set and later use it as a historical comparison.
2. Use the Diff Viewer toolbar to view any differences.
Tips: l
To switch the contents of the left pane to the right pane, and the contents of the right pane to the left, click .
l
You can also open files to compare by clicking at the top of each pane.
beside the drop-down list
Export Data with One Click Export
Use One Click Export to quickly export data to an Excel report. You can also export data and include a linked query in the file. A linked query lets you create a "live" Excel report that can be refreshed dynamically. Because a linked query contains the underlying SQL for a report, each time you refresh the report the query executes and retrieves the latest data. The dynamic nature of linked query reports makes them ideal for distribution to users who need to see changes to data on demand without waiting for new static reports to be distributed.
Click here to view a video of this feature.
Notes: l
Before you can export to Excel, the Primary Interop Assemblies (PIAs) for your version of Excel must be installed.
l
Use the Export wizard if you need to specify column delimiters and advanced field options when exporting data.
40
Toad for Data Analysts User Guide
Query
To export data in one click
1. Select the range of data to export or click any row in a data grid to export all data.
2. Right-click the selected range or data grid and select Quick Export.
3. Select an export option. Review the following for additional information:
Icon Option
Excel File
CSV File
HTML File
Excel
Instance
Excel
Instance at active cell
Excel Pivot
Table
Excel Pivot
Table at active cell
Description
Export data to an Excel file. The file is automatically saved under a default name in the default export folder.
Export data to a CSV file (comma separated value file).
The file is automatically saved under a default name in the default export folder.
Export data to an HTML file. The file is automatically saved under a default name in the default export folder.
Export data to an Excel instance. Data is copied to a clipboard, Excel is launched, and a worksheet is populated with data. You can save the worksheet under a name and folder you specify or in the default export folder.
Export data to an active cell in Excel. First open Excel and select a cell. Then select the Excel Instance at
active cell option.
Export data to an Excel pivot grid report. See the Excel documentation for information on creating a Pivot
Table report with external data.
Export data to an active cell for an Excel Pivot Table report. First open Excel and select a cell. Then select the Excel Pivot Table at active cell option.
41
Toad for Data Analysts User Guide
Query
42
Icon Option
Excel
Linked
Query
Excel
Linked
Query at active cell
Excel
Linked
Query with pivot table
Excel
Linked
Query at active cell with pivot table
Excel
Column
Chart
Description
Export the underlying query for data to Excel.
Export the underlying query for data to an active cell in
Excel. First open Excel and select a cell. Then select the
Excel Linked Query at active cell option.
Export the underlying query for data to an Excel Pivot
Table report. See the Excel documentation for information on creating a pivot grid report with external data.
Export the underlying query for data to an active cell for an Excel Pivot Table report. First open Excel and select a cell. Then select the Excel Linked Query at
active cell with pivot table option.
Export data to an Excel chart instance. Data is copied to the clipboard, Excel is launched, and a chart is created with the data. You can then modify the chart's design and save the Excel file.
Tip: To refresh data in a linked query report, click in Excel's External Data
toolbar. This executes the underlying query for the report. See "Share Excel
Linked Queries" (page 43) for more information about creating and using linked
queries.
Note: If the window containing data does not have the focus when you select a One
Click Export option, the following message displays: "Export did not find any results sets to process".
Tip: You can specify a default export folder in Tools | Options | Environment
| One Click Export.
Toad for Data Analysts User Guide
Query
Share Excel Linked Queries
You can use linked queries to create "live" Excel reports that can be refreshed dynamically.
Because a linked query contains the underlying SQL for a report, each time you refresh the report the query is executed and the latest data is retrieved. The dynamic nature of linked query reports makes them ideal for distribution to users who need to see changes to data without waiting for scheduled updates or for new reports to be distributed.
Notes: l
Any user who opens an Excel linked query must have access to a user name and password for the queried database to refresh the data. If a user does not have access to the database, they can only see the original data in the spreadsheet.
l
If the Excel linked query was created from an ODBC connection that uses a Data
Source Name (DSN), the DSN must also exist on the computer where the Excel file is opened to refresh the data.
Scenario
You need to create an Excel linked query so that the Regional Sales
Manager, can track whether the Sales Representatives in his region meet their monthly and quarterly goals. By providing a linked query, you only have to create the query once, and then the Regional Sales
Manager can refresh the data at any time to view the latest sales information.
To create an Excel linked query
1. Connect to the database.
2. Create a query in the Query Builder or Editor.
3. Execute the query to display data results.
4. Select the result set and click one of the following options from the toolbar:
43
5. Save the Excel spreadsheet.
6. Email or upload the spreadsheet to a shared network folder to share it with colleagues.
Toad for Data Analysts User Guide
Query
44
To refresh data in an Excel linked query
1. Open the spreadsheet with the linked query in Excel. The original data from the query displays.
2. In Excel, select Data | Refresh to update the original data with the current data.
3. If prompted, enter a user name and password to connect to the database and refresh the data.
or
If the following error displays: "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified", you must specify the DSN used by the query on your computer. Complete the following steps to resolve this issue:
(Excel 2003) a. Click OK.
b. Select the Machine Data Source tab, and then click New.
c. Use the wizard to select a User Data Source and create a DSN that points to the database.
d. Click OK to return to Excel and open an ODBC Driver Connect window.
e. Enter a user name and password to refresh the data.
5
Report
Tutorial: Create a Toad Data Report
Use the Data Report Designer to design reports visually. Stored in .tdr files, data reports are
"live" reports that can be refreshed dynamically. What makes them dynamic is that they contain the underlying queries for report data sets. Each time a data report is opened, its query runs and the latest data is retrieved. The dynamic nature of data reports makes them ideal for distribution to users who need to see changes to data without waiting for scheduled updates or for new reports to be distributed.
The process of creating a data report has the following steps: l
Step 1: Run the Toad Data Report Wizard
l
l
Step 3: Use Styles to Format the Report Appearance
l
Step 4: Update Bands and Add Controls
Note: This procedure does not cover all of the possible steps of creating a data report. It only covers the steps required to create a report for the scenario.
Scenario
Your company wants to improve its global sales, starting with countries where it has a customer base but averages low sales. You created a query that displays countries with less than $500,000 in sales per fiscal year, but now you need to create a report to help represent and evaluate the results. The data should be grouped per country and show the total and average sales for each country. In addition, you want the report to look similar to the rest of the company's documents, which use specific colors and fonts.
Note: This scenario uses the data generated in
Step 1: Run the Toad Data Report Wizard
The Toad Data Report wizard creates an initial layout of the report based on options you select, including what columns to include, whether to group data, and the basic style.
To run the wizard
1. Right-click the data grid in the Results tab and select Send To | Data Report
Designer. The Toad Report Designer displays.
2. Select Standard Report and click Next.
3. Click to include all columns in the report and click Next.
Toad for Data Analysts User Guide
Report
4. Select COUNTRY_NAME and click , and then click Next. This groups the data by the country name so that each country is listed as a heading and its sales per year display below it.
Tip: You can create a secondary group by selecting another column and clicking again. A secondary group is not appropriate for this scenario, but it would be if the data included regions in each country or fiscal quarters. You would need to make the region or fiscal quarter a secondary group for the data to be organized appropriately.
5. Select the Sum and Avg checkboxes for the SUM(SALES.AMOUNT) row, and then click Next. These options calculate the sum and average sales amount for each country.
6. Select Outline 1 and click Next.
Tip: The Outline and Align Left options are good choices if you grouped the data.
7. Select Casual and click Next.
8. Enter Countries with Sales Less Than $500,000 in the Report Title field, and then click Finish. The initial report layout displays in the Report window with the information grouped under bands. For more information on bands, see Add Report
Bands in the Toad help.
9. Click Preview to see what the report looks like in print. Previewing the report makes it easier to see how the bands and their content display in the printable report.
Step 2: Update Fields
You can move, rename, and update the category of a field.
To update the fields
1. Complete the following steps to update the field category: a. Select the FISCAL_YEAR field in detailBand1.
b. Click directly above the field.
c. Click by the Format String field.
d. Clear the Prefix field and click OK.
2. Double-click the following fields and enter their new name:
Field
FISCAL YEAR
Band groupHeaderBand2
Name
Fiscal Year
46
Toad for Data Analysts User Guide
Report
47
Field
SUM(SALES.AMOUNT_SOLD)
Avg
Band groupHeaderBand2 groupFooterBand1
Name
Sales Amount
Average
3. Select the following fields one at a time and make them wide enough to see the full text: Sum (groupFooterBand1), Average (groupFooterBand1), and Grand Total
(reportFooterBand1).
4. Select the following fields one at a time and drag them to the one inch mark on the ruler: Sum, Average, and Grand Total.
5. Right-click the COUNTRY NAME field (not the COUNTRY_NAME field on the right) in groupHeaderBand1 and select Delete.
Note: The COUNTRY NAME field is a label that precedes the COUNTRY_NAME field value. If you preview the report before you delete the COUNTRY NAME field, the country displays as 'COUNTRY NAME Argentina'. It is clear that Argentina is the country name, so this field is redundant.
6. Select the COUNTRY_NAME field and drag it to align with the report title.
7. Select the COUNTRY_NAME field and make it three inches wide to accommodate long country names.
Step 3: Use Styles to Format the Report Appearance
The Data Report Designer uses styles to format different objects and kinds of data. Once you define a style, you can apply it to similar fields to create a consistent and easy-toupdate design.
To create, update, and apply styles
1. Complete the following steps to update the report title style: a. Select the Styles field in the Properties pane.
b. Click . The Styles Editor window displays.
c. Select Title.
d. Select the Foreground Color field, and then select MidnightBlue in the
Web tab.
Note: All colors in this scenario are from the Web tab.
e. Select the Font field and click . The Font window displays.
f. Select 22 in the Size field and click OK.
2. Complete the following steps in the Styles Editor window to create and define four new styles:
Toad for Data Analysts User Guide
Report a. Click four times in the Styles Editor window to create four new styles.
b. Set the following properties for the new styles:
First Style
Name
Background Color
Border Color
Borders
Font
Second Style
Name
Border Color
Borders
Font
Third Style
Name
Background Color
Font
Foreground Color
Fourth Style
Name
Font
Foreground Color
Properties
OddRow
WhiteSmoke
MidnightBlue
Bottom
Tahoma, 10pt
Properties
EvenRow
MidnightBlue
Bottom
Tahoma, 10pt
Properties
TableHeading
MidnightBlue
Tahoma, 10pt, bold
White
Properties
CountryName
Tahoma, 14pt, bold
Black
3. Complete the following steps to apply the new styles: a. Expand the Styles field in the Properties pane.
b. Select TableHeading in the Style field (under Styles) for the Fiscal Year and
Sales Amount fields in groupHeaderBand2.
48
Toad for Data Analysts User Guide
Report c. Set the following fields for [FISCAL_YEAR] and [SUM(SALES.AMOUNT_
SOLD)] in detailBand1:
Field
Even Style
Odd Style
Property
EvenRow
OddRow d. Select the COUNTRY_NAME field in groupHeaderBand1 and then select
CountryName in the Style field.
Step 4: Update Bands and Add Controls
Bands group the information layout in the report and you can add controls to include additional tables, images, fields, and other items in the report. For more information on controls, see Add Controls in the Toad help. For the scenario, you will expand bands, delete a band, and add a control.
1. Right-click pageHeaderBand1 and select Delete.
2. Complete the following steps to add a line under the report title: a. Select the groupHeaderBand1 and move it down half an inch.
Tip: It is helpful to expand a band before adding controls to give you plenty of room in which to work.
b. Drag Line from the Toolbox into reportHeaderBand1.
c. Expand it to the width of the page.
d. Drag and position it directly below the report title.
e. Enter 2 in the Line Width field in the Properties pane.
3. Select reportFooterBand1 and drag it down half an inch. This adds white space between the country information.
The Data Report Designer displays with the following layout:
49
Toad for Data Analysts User Guide
Report
50
4. Click Preview.
The print preview displays with the following layout:
Toad for Data Analysts User Guide
Report
51
5. To save the report, right-click the Data Report Designer tab and select Save File.
Manage Reports
About Managing Reports
Use the Report Manager to create and organize data reports, add existing Toad or Excel reports, or generate reports.
To create a report
1. Select Tools | Reports | Report Manager from the menu.
2. Right-click a folder and select Create Report.
3. Complete the wizard and design the report.
4. Save the report.
5. To add the report to the Reports Manager window:
Toad for Data Analysts User Guide
Report
52 a. Navigate to the open Reports Manager window.
b. Right-click the folder where you want to add the report, and select Add
Existing Report.
To generate an existing report
1. Select Tools | Reports | Report Manager from the menu.
2. Double-click the existing report.
3. Review the following for additional information:
Direction
Value
Select the direction of variable from the list.
Enter the value of the variable.
Note: Enter a percent (%) in this field to generate all values.
Tips: l
To add an existing Toad or Excel report to the Report Manager, right-click the Report
Manager window and select Add Existing Report.
l
To send a Toad or Excel report via email or to a shared folder or other location, rightclick the report, select Send To, and then select an option.
l
To share reports with other users, specify a shared network directory in Network Share
Options (Tools | Options | Environment | Network Share).
DB2 Reports
The following reports are available from the Reports Manager (Tools | Reports
| Reports Manager).
Report Name
Activity
ADMIN_LIST_
HIST_V82
Database
Partitions
DB Manager
Config Info
Description
Lists and describes activity reports that the Activity Monitor for the current DB2 for LUW database uses. This report also lists the switches required to gather data for a specific activity report. Toad uses the AM_BASE_RPTS table function to generate this report.
Displays information from the database history table for the DB2 for LUW database partition to which Toad is currently connected.
Toad uses the ADMIN_LIST_HIST table function to generate this report.
Shows information about each database partition on the current
DB2 for LUW database. Toad uses the DB_PARTITIONS function to gather this information from db2nodes.cfg.
Lists the database manager configuration parameters and their values defined for the current DB2 for LUW database.
Toad for Data Analysts User Guide
Report
Report Name Description
HEALTH_
CONT_HI
HEALTH_
CONT_HI_HIS
HEALTH_
CONT_INFO
HEALTH_DB_HI Shows the "health" status of the current DB2 for LUW database, including its highest current alert status. Toad uses the HEALTH_
DB_HI table function to generate this report.
HEALTH_DB_
HI_HIS
Shows the "health" history of the current DB2 for LUW database.
Toad uses the HEALTH_DB_HI_HIS table function to generate this report.
HEALTH_DB_
HIC
Identifies the containers that tablespaces in the current DB2 for
LUW database use and lists the highest current alert status for each container. Toad uses the HEALTH_CONT_INFO table function to generate this report.
HEALTH_DB_
HIC_HIS
Shows the "health" status of objects in the current DB2 for LUW database. Toad uses the HEALTH_DB_HIC table function to generate this report.s
Displays a "health" history for objects in the current DB2 for LUW database. Toad uses the HEALTH_DB_HIC_HIS table function to generate this report.
HEALTH_DB_
INFO
Shows the current "health" status of all containers that tablespaces in the current DB2 for LUW database use. Toad uses the
HEALTH_CONT_HI table function to generate this report.
Shows a "health" history for all containers that the tablespaces in the current DB2 for LUW database use. Toad uses the HEALTH_
CONT_HI_HIS table function to generate this report.
HEALTH_DBM_
HI
HEALTH_DBM_
HI_HIS
HEALTH_DBM_
INFO
HEALTH_TBS_
HI
Shows the highest current alert status for the current DB2 for LUW database. Toad uses the HEALTH_DB_INFO table function to generate this report.
Shows the "health" status for the current DB2 for LUW instance.
Toad uses the HEALTH_DBM_HI table function to generate this report.
Shows a "health" history at the database manager level for the current DB2 for LUW instance. Toad uses the HEALTH_DBM_
HI_HIS table function to generate this report.
Shows the highest current alert status for the current DB2 for LUW instance. Toad uses the HEALTH_DBM_INFO table function to generate this report.
Shows the "health" status of all tablespaces in the current DB2 for
LUW database. Toad uses the HEALTH_TBS_HI table function to generate this report.
53
Toad for Data Analysts User Guide
Report
Report Name Description
HEALTH_TBS_
HI_HIS
HEALTH_TBS_
INFO
Index Statistics
Installed DB2
Products
Installed DB2
Products_V82
Shows a "health" history for tablespace in the current DB2 for
LUW database. Toad uses the HEALTH_TBS_HI_HIS table function to generate this report.
Shows the highest current alert status for each tablespace in the current DB2 for LUW database. Toad uses the HEALTH_TBS_
INFO table function to generate this report.
Displays statistics for the indexes under the current schema for the
DB2 for LUW database and flags those indexes that need reorganization. Toad uses the REORGCHK_IX_STATS procedure to generate this report.
Lists the DB2 for LUW 9 products currently installed on your system. Toad uses the ENV_GET_PROD_INFO table function to generate this report. Products can include the following: RTCL
DB2 Run-Time Client CONSV DB2 Connect Server (any edition)
CONPE DB2 Connect Personal Edition
Lists the DB2 for LUW 8 products currently installed on your system. Toad uses the ENV_GET_PROD_INFO table function to generate this report. Products can include the following: l
ADCL DB2—Application Development Client l
ADMCL DB2—Administration Client l
CONEE DB2—Connect Enterprise Edition, DB2 Connect
Unlimited Edition, or DB2 Connect Application Server
Edition l
CONPE DB2—Connect Personal Edition l
CUBE DB2—Cube Views l
DLM DB2—Data Links Manager l
ESE DB2—Enterprise Server Edition l
EXP DB2—Express Edition or DB2 Express Edition processor option l
GSE DB2—Spatial extender l
PE DB2—Personal Edition l
QP DB2—Query patroller l
RTCL DB2—Run time client l
WM DB2—Warehouse Manager l
WSUE DB2—Workgroup Server Unlimited Edition
54
Toad for Data Analysts User Guide
Report
Report Name
Instance
Information_V82
Recommendations for Activity
Reports
SNAP_GET_
CONTAINER _
V82
SNAP_GET_DB_
V82
SNAP_GET_
DYN_SQL_V82
SNAP_GET_
TAB_V82
SNAP_GET_
TBSP_PART_
V82
SNAP_GET_
TBSP_V82
SNAPSHOT_
AGENT_V82
System
Information_V82
Description
Lists details about the current DB2 for LUW instance. Toad uses the ENV_GET_INST_INFO table function to generate this report.
Provides recommendations (in English) for the various activity reports that the activity monitor uses. Toad uses the AM_BASE_
RPT_RECOMS table function to generate this report.
Displays information and statistics about each container that tablespaces in the current DB2 for LUW 8 database use. To generate this report, Toad uses the SNAP_GET_CONTAINER table function to retrieve information from the tablespace_ container logical data group.
Lists information and statistics captured for the current DB2 for
LUW 8 database. To generate this report, Toad uses the SNAP_
GET_DB table function to retrieve information from the database and detail_log logical data groups.
Lists statistics and information about the dynamic SQL statements executed against the current DB2 for LUW 8 database use. To generate this report, Toad uses the SNAP_GET_DYN_SQL table function to retrieve information from the dynsql logical data group.
Lists information and statistics about the tables in the current DB2 for LUW database 8. To generate the report, Toad uses the SNAP_
GET_TAB table function to retrieve information from the table logical data group.
Lists information and statistics for the database partitions that make up each tablespace in the current DB2 for LUW 8 database.
To generate this report, use the SNAP_GET_TBSP_PART table function to retrieve information from the tablespace_nodeinfo logical data group.
Lists information and statistics for each tablespace in the current
DB2 for LUW 8 database. To generate the report, Toad uses the
SNAP_GET_TBSP table function to retrieve information from the tablespace logical data group.
Lists the agents working for the various applications connected to the current DB2 for LUW 8 database. To generate the report, Toad uses the SNAPSHOT_AGENT function to retrieve information from the application snapshot, especially from the agent logical group.
Displays information about the operating system in which the current DB2 for LUW 8 database operates and about the CPUs
55
Toad for Data Analysts User Guide
Report
Report Name
Table Statistics
Column View
Table Statistics
Description configured on this operating system. Toad uses the ENV_GET_
SYS_INFO table function to generate this report.
Displays statistics for the tables under the current schema in the
DB2 for LUW database and flags those tables that need reorganization. Toad uses the REORGCHK_TB_STATS procedure to generate this report.
Displays statistics for the tables under the current schema in the
DB2 for LUW database and flags those tables that need reorganization. Toad uses the REORGCHK_TB_STATS procedure to generate this report.
MySQL Reports
The following reports are available from the Reports Manager (Tools | Reports
| Reports Manager).
Report Name
Help Topic
Description
Displays the first 10 rows of the mysql.help_topic table.
ODBC Reports
The following reports are available for the Toad Sample Database in the Reports Manager
(Tools | Reports | Reports Manager):
Report Name
Customer orders
Customer list
Items to order
Description
Displays customer orders for contact IDs less than 10 from the Toad sample database. It is an example of master detail display using a single result set.
Displays a list of customers from the Toad sample database.
Displays items in stock that have a quantity of less than 50 and should be reordered from the Toad sample database.
Oracle Reports
The following reports are available from the Reports Manager (Tools | Reports
| Reports Manager).
Cluster Reports
56
Toad for Data Analysts User Guide
Report
Report Name
Clusters
Description
Displays cluster information, including the cluster type, definitions, storage parameters, and affected tables.
Other Reports
Report Name
Invalid objects
Loads into shared pool
Description
Displays any invalid objects for the selected schema and includes a subtotal of all invalid objects for that owner.
Displays packages that have been loaded five or more times, into the
Oracle shared pool.
Note: You must have DBA privileges for this report.
Displays any objects in the SYSTEM tablespace that are not owned by SYSTEM.
Non-system objects in
SYSTEM tables
Oracle initialization parameters
Tablespaces near capacity
Total shared pool reload stats
User hit ratios
Displays the values for all parameters defined in the PFILE for the selected user.
Displays tablespaces that over 90% full, and do not have the autoextend feature enabled.
Displays the number of times objects in the shared pool were reloaded.
Note: You must have DBA privileges for this report.
Displays the buffer cache hit ratio users and includes consistent gets, blocked gets, and physical reads.
Displays values for resource usage such as CPU used and SQL*Net roundtrips for each user.
User resource usage
Sequence reports
Report Name
Sequences
Sequences near max
Description
Displays the sequences that are within 10% of the maximum value.
Any sequences that do not have a maximum value set, or those that cycle are excluded from the report.
Displays the sequences that are within 10% of the maximum value.
Any sequences that do not have a maximum value set, or those that cycle are excluded from the report.
Stored Program Reports
57
Toad for Data Analysts User Guide
Report
Report Name
Arguments of stand-alone stored programs
Object type bodies
Object types
Description
Displays any parameters required for the selected stored procedure.
Displays the body or source code for a selected object.
Package bodies
Package specifications
Stand-alone stored programs
Stored functions
Stored object with source
Stored procedures
Synonym Reports
Displays the type of objects owned by a user, including whether the objects are valid and when they were created or last modified.
Displays the body or source code for a selected package
Displays specifications for a selected package, including whether it is valid and when it was created or last modified.
Displays the source code for a stored program, including the type of program and the last time DDL was generated.
Displays a list of stored functions for a selected owner.
Displays a list of all stored programs including their source.
Displays the source for stored procedures for a selected owner.
Report Name
Synonyms
Description
Displays information for each synonym, including the owner, table owner and name, and the DB link.
Table Reports
Report Name
Indexes
Non-indexed tables
Description
Displays details for the index definition, storage parameters, and columns included in the index.
Displays any tables that have not been indexed for the selected database.
58
Toad for Data Analysts User Guide
Report
Report Name
Table comments
Tables
& columns
Description
Displays any comments for the selected table.
Tables
& indexes
Trigger Reports
Displays all columns for a selected table, including the maximum transactions, used/free blocks, free lists and groups, min/max extents, and columns included in this index.
Displays any indexes for a selected table, including the status, uniqueness, and columns included in the index.
Report Name
Triggers
& columns
User-defined Reports
Description
Displays triggers for a selected table, including the trigger event, status, WHEN clause, and columns associated with the trigger.
Description
Displays a sample user report based on a select * from dual query.
Report Name
Sample
View Reports
Report Name
View comments
Views & columns
Description
Displays any comments for the selected view.
Displays all columns for a selected view, including the query and columns included in the view.
SQL Server Reports
The following reports are available from the Reports Manager (Tools | Reports
| Reports Manager).
DBA Reports
Report Name
All jobs
Backup history
Description
Displays all scheduled SQL Server jobs and the job owner, organized by server.
Displays the backup start date, type, and device used for the backup for a specified database for a set number of days.
59
Toad for Data Analysts User Guide
Report
Report Name
Backup status
Current lock report
Database configuration options
Database settings
Database user details
Display errors
Drive space usage
Foreign key sequence
Index description
Job details
Description
Displays the database name, date of the last backup, days since the last backup, and the type of backup performed.
Displays any locks on the server, including the database name, object or index name, type of lock, resource, mode, and status.
Displays configuration options for each database on the specified server.
Displays any common options and their values for all the databases on your server.
Displays the user name, roles, objects, granted/denied status, and column permissions for each database.
Displays a log file without entries for log backups. This is useful when you have a number of log backup entries and you need to locate non-backup errors.
Displays space for all databases on the server, including free space, space used, maximum size, and growth type.
Displays tables in the order you can either populate or delete from them without violating any foreign key constraints. Objects with the lowest wave number indicate that they can be deleted with the fewest number of foreign key references. Objects with the highest wave number should be populated first.
(SQL Server 2000 only) Displays all indexes for the current database sorted by table. Index information includes whether it is clustered, unique, index keys, and the index size. run frequency, and the maximum duration.
(SQL Server 2000 only) Displays all SQL Server jobs, including whether they are scheduled, enabled, start date and time,
Displays the number of rows for all tables on a server that contain a clustered index.
Row count for tables with clustered index
Total rows and space used
User permissions
Displays the total number of rows and space used for each table or view in the current database, including the reserved rows, unused rows, and index size. This report is sorted in descending order by reserved rows.
Displays users permissions, grouped by role name and object type.
60
Toad for Data Analysts User Guide
Report
Other Reports (SQL Server 2005 only)
Report Name
Configuration change history
Schema change history
Table Reports
Description
Displays a history of all sp_configure and Trace Flag Changes recorded by the default trace.
Displays a history of all committed DDL statement executions recorded by the default trace.
Report Name
Indexes
Non-indexed tables
Table constraints
Description
Displays index information for a selected table, including whether the index is clustered, unique, ignores duplicate keys, allows page/row locks, and a list of indexed columns.
Displays any tables that have not been indexed for the selected database.
Displays any check constraints for a selected table, including whether the constraint is enabled, valid data, and affected columns.
Displays any extended properties for a selected table.
Table extended properties
Table relationships
Tables and columns
Tables and indexes
Displays any foreign key constraints for a selected table, including whether the constraint is enabled, referenced tables, and referenced keys.
Displays all columns for a selected table, including the data type, default value, whether it allows null values, and for SQL Server
2005 any extended properties.
Displays any indexes for a selected table, including the name, columns included in the index, and whether it is unique or clustered.
User-defined Reports
Report Name
Stored procedures
Description
Displays stored procedures for a selected database, including their status, status, replication information, schema version, statistics, and procedure text.
61
Toad for Data Analysts User Guide
Report
Publish and Share Reports
Toad provides multiple ways to publish and share information with your business community. Use the following methods to publish and share information from the Project
Manager, Reports Manager, and Automation: l
Email reports and files, including Database Diagrams, Query Builder queries, SQL scripts, and results for reports, queries, and scripts.
l
Share reports and files in a central location such as the Toad shared folder.
l
Add reports and files to a ZIP folder or file.
l
Publish reports and files to a web site.
You can use the following methods to publish and share information:
To email from...
Project Manager
Reports Manager
Automation
To publish to a central location from...
Project Manager
Reports Manager
Do this...
Right-click a report or file and select Send To | Mail
Recipient.
Drag the Send Email activity to the Automation workflow and attach files as needed. The email is sent when the automation script executes.
Do this...
Automation
To send to a zip file...
Project Manager
Reports Manager
Automation
Right-click a report or file and select Send To | Toad
Shared. The file is sent to the Toad shared folder specified in
Tools | Options | Environment | Network Share.
Drag the Copy File activity to the automation workflow.
Specify the file to copy or move and a destination folder.
This can be any folder, including the Toad shared folder, or a network folder. The file is copied or moved when the automation script executes.
Do this...
Right-click a report or file and select Send To | Compressed
(zipped) Folder.
Note: This function requires that ZIP files be associated with the Compressed (zipped) Folders feature instead of WinZip or another ZIP file handler.
Drag the Zip File activity to the workflow. Add reports and files to the Zip file and specify a file name with a .zip
62
Toad for Data Analysts User Guide
Report
63 extension. The ZIP file can then be emailed with the Send
Email activity or copied with the Copy File activity.
Do this...
To publish to a web site...
Project Manager or
Reports Manager
Right-click a report or file and select Send To | Web
Publishing Wizard. Complete the wizard to specify a URL and directory for the file.
Tips: l
To export a Toad report to a file that can be read by other applications, double-click a report in the Reports Manager, click in the Report Preview window, select a file format, and add the file to a project. Share or publish the file using the Project
Manager functions.
l
To capture report results in a file, add the
automation activity. This activity runs a Toad report and saves the results in a file format you select. Share or publish the file using the Automation functions.
l
To execute and save a query in a file, add the Select To File automation activity. This activity runs a query or SQL script and exports the results to an Excel spreadsheet.
Share or publish the spreadsheet using the Automation functions.
6
Automate
Scenario: Automate a Query and Email the Report
Scenario
You need to create an Excel report that contains current regions and addresses and email it to your manager every week.
Note: This scenario uses the Toad Sample (Access) database that ships with Toad for
Data Analysts.
To automate a task for this scenario
1. Connect to the Toad Sample (Access) database in the Navigation Manager.
2. Enter the following statements in the Editor and save them to a single file named
AutomationTest.sql:
Select * from region;
Select * from address;
3. Select Tools | Automation from the menu.
4. To send yourself an email if an error occurs, click Settings in the Automation design window and enter the following:
Stop or continue on error
Send email when an error occurs
Compose Email
Select Stop On Error
Select this option.
Email Server
Settings
Click Compose Email and enter your email address in the
To and the From fields.
In the Compose Email form, click Email Server Settings and enter your SMTP server address and the port number.
5. Click the Select To File database activity in the toolbox to add it to the design window.
6. Click the File_1 activity and select Toad Sample Database in the connection field.
Toad for Data Analysts User Guide
Automate
7. Click the File_1 activity and enter the following in the Activity Input window:
SQL file
Export file
Select AutomationTest.sql.
Select the following options: l
Destination—Ensure that the Excel file option is selected.
Then, select a folder and enter AutomationTestExcel as the file name.
l
Add Date/Time suffix to filename—Select this checkbox.
8. Click the Send Email file activity in the toolbox to add it to the design window.
9. Click the Send Email activity and enter the following in the Activity Input window:
To
From
Add
Attachments
Subject
Body
Enter your email address.
Enter your email address.
Click Add Attachments. Select AutomationTestExcel from
Activity Reports and click Add. Click the X in the upper-right corner of the dialog.
The file is added as an email attachment.
Enter Weekly Report.
Enter the following: Attached is a copy of the weekly regions and addresses report.
Click Email Server Settings and enter your SMTP server address and port number.
Server
Settings
10. Save the Automation script.
11. Click Test on the wizard bar to ensure that the script works. The automation script is compiled, then executed. All results display in the Log window.
12. Review the log and click the link to the Excel file generated to open the Excel file in Toad.
Notice that the results of each SQL statement are in a different worksheet.
13. To schedule the automation script to run at a later time, click Schedule on the wizard bar.
14. Complete the following fields:
Task Tab
Set password
Description
Click this button and enter and confirm your O/S password.
65
Toad for Data Analysts User Guide
Automate
66
Schedule
Schedule task
Start time
Description
Select Once.
Select a time that is 2 minutes from the current time.
15. Check your email for confirmation of execution as well as the status of the job manager window.
Automate Tasks
Use Automation to schedule a single script to run reports and queries, save results in Excel spreadsheets, and distribute results to the business community via email. You can schedule scripts that perform long-running tasks to run when database activity is light.
You can also use variables in automation scripts. With variables, you can update information that may be different each time you run the script, such as the department name, revenue,
fiscal quarter, or product name. See "Use Variables in Automation" (page 83) for more information.
For example, assume you are an analyst at Nick's Flicks movie rentals. You need to run inventory and movie rental reports on a daily basis and distribute them to managers of the inventory department. Using Toad, you create an automation script that runs the reports, exports them to Excel spreadsheets, and emails the spreadsheets to the inventory department everyday at 2:00 AM.
Troubleshooting: l
If Toad displays a "Variable must be initialized before referencing itself" error, you
l
You must surround a variable name with the # sign (for example, #sleep#).
Note: This topic focuses on information that may be unfamiliar to you. It does not include all step and field descriptions.
To automate tasks
1. Click Automate.
2. Select the Settings icon in the script design window to specify the script settings before building your script. Use the Activity details pane in the bottom portion of the
Automation window to enter your settings. Review the following for additional information:
Toad for Data Analysts User Guide
Automate
Activity
Input
Stop or continue on
Error
Send email when error occurs
Select Stop On Error to stop the script if an error occurs.
Use relative path to find
SQL files
Select this option to send an email on script error.
If selected, you must also click Compose Email to compose the email message and to edit the Email Server Settings.
Note: When you specify the error email settings, Toad saves your settings and uses them in all subsequent automation scripts.
Select to use a relative path that does not include the drive or full path for all activities in the script. This is useful if you want to share your automation scripts with colleagues, use them with version control, or place them on a shared network folder.
Select to embed the actual SQL from SQL files in the script.
This makes it easier to share the script with colleagues.
Embed
SQL into
Automation script
Truncate log
Run Mode
Select to overwrite the log file each time the script runs.
Select Test mode to run your script in test mode using the database connection specified under Test settings.
Select Production mode to run your script in production mode using the database connection specified under Production settings.
Note: The default connection is the currently active, open connection.
Activity Info
Name Enter a script name.
3. To build your script, click an activity in the Toolbox, or drag an activity from the
Toolbox to the Automation script design window. Repeat to add additional activities to your script.
Note: You must drag the activity to the , then release the mouse button after you see the activity's icon replace the .
4. For each activity in your script, select the activity in the design window and then
67
Toad for Data Analysts User Guide
Automate
68 specify the activity's properties in the Activity details pane.
See the following topics for details about each activity and its properties: l
Use Database Automation Activities (page 69)
l
Use File Automation Activities (page 73)
l
Use System Automation Activities (page 79)
Tip: You can save an activity and its properties as a template to reuse in other scripts.
Right-click the activity in the design window and select Save As Template. After you create the first template, a Templates toolbox displays.
Note: Click Settings in the design window at any time to go back and review the
Automation script settings.
5. When you finish building your script, select one of the following actions from the
Automation toolbar or the Wizard bar:
Add to Project
Save
Run
Schedule
Add an automation script to the current project in the
Project Manager. The script is automatically placed in the project's Automation Scripts folder.
Save an automation script (.tas) in a folder on a local or network drive.
Run an automation script before scheduling it. The script executes once and the execution log is displayed in the
Log window. Resolve any problems that cause activities to fail, or disable failed activities before scheduling the script.
Tips: l
Press F5 to run the automation script.
l
To view the script log, select the Log tab or select
View | Output.
Schedule an automation script in the Job Manager. You can schedule a script to execute once or to run periodically
at a defined interval. See "Execute Automation Scripts"
(page 90) for more information.
Tips: l
Double-click an activity in the script design window to open the Activity Properties pane in a format used in earlier versions of Toad.
l
Right-click within the script design window and select Print Script to print the script's workflow diagram.
Toad for Data Analysts User Guide
Automate
Use Database Automation Activities
You can use the following activities in automation scripts.
Note: When building an automation script, you must have the appropriate connections open for database activities.
Tip: You can save an activity and its properties as a template to reuse in other scripts. Rightclick the activity in the design window and select Save As Template. After you create the first template, a Templates toolbox displays.
Activity
Database
Connection
Select to File
Description
In previous versions of Toad, the Database Connection activity was required in order to specify database connection details.
In the current version of Toad, the database connection details are specified in each activity's properties.
Notes: l
If the connection was open before the script ran, it closes the connection once the activities in the connection box are complete.
l
You can include connections for multiple databases in the same automation script.
Execute an existing SQL script or Query Builder query and export the results to an Excel, HTML, or CSV file. You can then use additional activities to add the exported result file to a zip file, attach the file to an email, or copy the file.
Review the following for additional information: l
Row count variable—Enter a name for the row count variable.
The value assigned to this variable equals the number of rows returned from the activity. You can use this variable with the
this field.
l
SQL—Manually enter SQL or select a SQL script or Query
Builder query to run. For SQL scripts, you can create a new worksheet for the results of each SELECT statement in a script by entering GO after each statement.
Note: To manually enter SQL in the text box, deselect Link
SQL file.
l
Export file—Click the drop-down list to select the export file type. Then, select the file location and enter the name. You can use a variable in this field by entering the number sign before
69
Toad for Data Analysts User Guide
Automate
Activity
Execute Script
Select to
Editor with
Results
Description and after the variable (#VariableName#). If you select Excel
file, you can append the date and time that the file was generated to the file name as a suffix.
Note: You can only use one variable per field or file name (a suffix counts as one variable for a file name).
Execute an existing SQL script or Query Builder query.
Review the following for additional information: l
Row count variable—Enter a name for the row count variable.
The value assigned to this variable equals the number of rows returned from the activity. You can use this variable with the
this field.
l
SQL—Manually enter SQL or select a SQL script or Query
Builder query to run. For SQL scripts, you can create a new worksheet for the results of each SELECT statement in a script by entering GO after each statement.
l
Result variable—Enter a name for the result variable, which contains a data table with the results of the execution script.
You can use the result variable with the Loop Dataset activity.
See "Use System Automation Activities" (page 79) for more information.
Execute an existing SQL script or Query Builder query and save it and any results sets in a Toad editor file (.tef).
This file format is useful for building scripts that have large result sets that you do not want to continue executing or for saving results when you have not finished building a script.
Review the following for additional information: l
Row count variable—Enter a name for the row count variable.
The value assigned to this variable equals the number of rows returned from the activity. You can use this variable with the
this field.
l
SQL—Manually enter SQL or select a SQL script or Query
Builder query to run. For SQL scripts, you can create a new worksheet for the results of each SELECT statement in a script by entering GO after each statement. l
Editor File—Select the file location and enter the name. You can use a variable in this field by entering the number sign before and after the variable (#VariableName#).
70
Toad for Data Analysts User Guide
Automate
Activity Description l
Suffix—Select a suffix to append to the file name. The suffix can be the date and time that the file was generated or the content of a variable that you define with the Set Variable
system activity. See "Use System Automation Activities" (page
Note: You can only use one variable per field or file name (a suffix counts as one variable for a file name).
Export Wizard Export data from databases, tables, views, or a query into a CSV,
Excel, or other file.
Review the following for additional information: l
Export template—You can select an existing template, edit an existing template, or create a new template.
l
Use automation connection—Select this option to use the connection associated with the database activity. Clear the checkbox to use the connection associated with the export template.
Import Wizard Import data from a CSV, Excel, or other file into a new table or append to an existing table.
Review the following for additional information: l
Import template—You can select an existing template, edit an existing template, or create a new template.
l
Use automation connection—Select this option to use the connection associated with the database activity. Clear the checkbox to use the connection associated with the import template.
Toad Report Use this activity to open one or more Toad data reports and export the contents as a PDF, HTML, Excel, CSV, RTF, or MHT file. You can then add another activity to your script to zip the new file, attach it to an email, or save it to a new location.
Review the following for additional information: l
Row count variable—Enter a name for the row count variable.
The value assigned to this variable equals the number of rows returned from the activity. You can use this variable with the
this field.
l
Report files—Select one or more Toad data reports from the
Project Manager or other location, or edit an existing report.
l
Export file—Select the file type and location and enter the
71
Toad for Data Analysts User Guide
Automate
Activity
Toad Pivot
Grid
Clean Data
Description name. You can use a variable in this field by entering the number sign before and after the variable (#VariableName#).
l
Suffix—Select a suffix to append to the file name. The suffix can be the date and time that the file was generated or the content of a variable that you define with the Set Variable
system activity. See "Use System Automation Activities" (page
Note: You can only use one variable per field or file name (a suffix counts as one variable for a file name).
Refresh an existing pivot grid and export results to an Excel, HTML, or CVS file. You can then add another activity to your script to zip the new file, attach it to an email, or copy it to a new location.
Review the following for additional information: l
Row count variable—Enter a name for the row count variable.
The value assigned to this variable equals the number of rows returned from the activity. You can use this variable with the
this field.
l
Pivot file—Select a Toad pivot file from the Project Manager or other location, or edit an existing pivot file.
l
Export file—Select the file type and location and enter the name. You can use a variable in this field by entering the number sign before and after the variable (#VariableName#).
l
Suffix—Select a suffix to append to the file name. The suffix can be the date and time that the file was generated or the content of a variable that you define with the Set Variable
system activity. See "Use System Automation Activities" (page
Note: You can only use one variable per field or file name (a suffix counts as one variable for a file name).
Execute data cleansing to create a new data set by filtering an existing data set or data source.
Review the following for additional information: l
Data cleansing creates a new, cleansed table and leaves the source table intact. Implement a data hub repository or some form of internal data store. Alternatively, you can specify a schema or database to create, or alter and drop tables.
l
Each data hub table needs a name and Test Representation
Language (TRL) representation. Groups of tables, data
72
Toad for Data Analysts User Guide
Automate
Activity Description validation actions, and the sequential flow between them are grouped and stored into projects displayed in the workbench.
l
Data Cleansing file—Select a data cleansing file or edit an existing file.
l
Row count variable—Enter a name for the row count variable.
The value assigned to this variable equals the number of rows returned from the activity. You can use this variable with the
this field.
l
Export to file—Select a file location and enter the name. You can use a variable in this field by entering the number sign before and after the variable (#VariableName#).
l
Export to local storage—Select or create a database and table in local storage to receive cleansed data.
Notes: l
Status—Select Enabled to include the activity in script execution. Select
Disabled to disable the activity, for example, when testing other activities. Or right-click the activity in the design window and select/deselect Enabled.
l
Stop on Error—Allows you to select, for each activity, whether to stop or continue execution if Toad encounters an error.
l
Select the Log tab to review a script's execution log.
l
Automation does not support positional parameters denoted by a question mark.
l
For each activity, you can specify the database connection in the activity's properties. The default connection is the currently active, open connection.
Use File Automation Activities
You can use the following activities in automation scripts.
Tip: You can save an activity and its properties as a template to reuse in other scripts. Rightclick the activity in the design window and select Save As Template. After you create the first template, a Templates toolbox displays.
Activity
Copy File
Description
Copy or move one or more files to a shared folder where they can be accessed by your business community. You can copy or move a file generated by other activities in the automation script and overwrite an existing copy of a destination file.
73
Toad for Data Analysts User Guide
Automate
Activity
Delete File
Log Comment
Zip Files
Description
Review the following for additional information: l
Source file—Select a single file to copy, or use an asterisk
(*) as a wildcard to select multiple files in the same directory to copy.
l
Copy name—Enter the name. You can use a variable in this field by entering the number sign before and after the variable (#VariableName#).
l
Suffix—Select a suffix to append to the file name. The suffix can be the date and time that the file was generated or the content of a variable that you define with the Set
Variable system activity. See "Use System Automation
Activities" (page 79) for more information.
l
Move/Copy—Select Move to move a file from the source folder to a destination folder. Select Copy to copy the file to the destination folder.
Notes: l
If you want to use this activity for files generated by other automation activities, those activities must precede this one. The filenames and paths specified should match the directories and names displayed in properties for the preceding activities.
l
You can only use one variable per field or file name (a suffix counts as one variable for a file name).
Delete one or more files from a specified location. You can use this activity to delete files that are created earlier in the script.
Note: You can use an asterisk (*) in the FileName field as a wildcard to select multiple files in the same directory to delete.
Writes a comment to the scripts's log.
Create a zip file and add files to it. Files generated with other activities can be added to the zip file. You can then email the zip file to colleagues.
Review the following for additional information: l
Archive name—Select a location and name for the zip file.
You can use a variable in this field by entering the number sign before and after the variable (#VariableName#).
l
Encryption—Select whether to create a zip file without encryption (Standard) or to encrypt the zip file.
Note: If you encrypt the zip file, you must have a zip utility that can support 128-bit or 256-bit decryption.
74
Toad for Data Analysts User Guide
Automate
Activity
Find and Replace
Description l
Zip all files in this directory—Select a directory. All files in the directory will be included in the zip file.
l
Source files—Select one or more files. You can select files that are generated by the automation script.
Notes: l
If you want to use this activity for files generated by other automation activities, those activities must precede this one. The filenames and paths specified should match the directories and names displayed in properties for the preceding activities.
l
You can only use one variable per field or file name (a suffix counts as one variable for a file name).
This activity opens one or more files and performs a find and replace within those files. You can write the results to a different location and file name.
Review the following for additional information: l
Find/Replace—You can have multiple Find/Replace tasks within one activity. You can specify a different set of properties for each Find/Replace task.
l
Source file—Select the file in which to perform the find and replace activity. To select multiple files for one
Find/Replace task, use standard wildcard characters in the file name.
l
Find—Enter the content to find.
l
Replace with—Select the type of replacement content: a value, contents from a file, or a variable.
l
Set value—Enter the replacement value, enter the replacement variable, or select a file containing replacement content.
You can use a variable in this field by entering the number sign before and after the variable (#VariableName#). In the following example, if variable X has a value of 10, the updated file would display "Region 10" instead of
"Region".
l
Save file—Select a location and file name.
Default file is the source file.
75
Toad for Data Analysts User Guide
Automate
Activity
Send Email
Description l
Suffix—Select a suffix to append to the file name. The suffix can be the date and time that the file was generated or the content of a variable that you define with the Set
Variable system activity. See "Use System Automation
Activities" (page 79) for more information.
Notes: l
If you want to use this activity for files generated by other automation activities, those activities must precede this one. The filenames and paths specified should match the directories and names displayed in properties for the preceding activities.
l
You can only use one variable per field or file name (a suffix counts as one variable for a file name).
l
Use drag and drop or up/down arrows to change the order of multiple Find/Replace tasks in one activity.
Send an email to notify yourself or colleagues about the automation script status. The message automatically includes execution status for each activity that precedes the email activity.
You can also attach files generated by other activities and include a log file or error messages in the email.
Note: To use this activity, an SMTP service must be running.
Review the following for additional information: l
Enter recipient email address, subject line, and body text.
l
Email Server Settings—Specify SMTP server name and port.
Default settings are the Email Server Settings specified in
Settings properties.
l
Add Attachments—Click to add files created by this script or to browse for other files to add as attachments.
l
Use file for body—Select a file to use as the body of the email. This is useful if you need to send an email to a mobile device that does not support attachments. For example, you could send the results of an Execute Script activity in the body of the email.
If you use the Toad Report activity, you can select
HTML as the output format type. You can then select that
HTML file as the body for the email to produce a more professional looking email version of the report.
You can also customize the file with the Find and Replace activity.
Notes:
76
Toad for Data Analysts User Guide
Automate
Activity
FTP File
Run Automation
Script
Description l
For the To, CC, Subject, and Body fields: You can use a variable in this field by entering the number sign before and after the variable (#VariableName#).
l
You can only use one variable per field or file name (a suffix counts as one variable for a file name).
Upload or download a file using an FTP or SFTP connection.
Review the following for additional information: l
Select an FTP connection—Select an FTP connection or define a new connection.
l
Transfer ONLY if—Select this option to set conditions for
FTP transfer, and then select a condition from the list. If you select this option, the FTP activity only runs if the conditions you specify are met. For example, you would select remote file exists if a vendor uploads a file to the
FTP site containing a mailing list l
Local directory—If you selected local directory exists or
local file exists, select the local directory to check.
l
Local file—If you selected local file exists, enter the name of the local file.
l
Remote directory—If you selected remote directory exists or remote file exists, select the remote directory to check.
l
Remote file—If you selected remote file exists, enter the name of the remote file.
l
Define Operations—Review the following for additional information: o Use file mask—Select this option if you want to match files that use the file mask specified in the
File mask field at the bottom of this page.
o Move files—Select whether to move the files from the source location to the target location when uploading or downloading the files.
Run another automation script in your current automation script.
Review the following for additional information: l
Automation script—Select an automation script (.tas file).
77
Toad for Data Analysts User Guide
Automate
Activity
Compare Data
Description l
Return code—Enter a variable name, such as "RC," for the return code. Return code values are: o 0 = Successful execution o 999 = An error occurred during execution o 111 = An error occurred, but you selected continue on error.
You can use this variable with the If..Condition activity.
Open a Toad data compare project and export the contents as a
PDF, HTML, Excel, CSV, RTF, or MHT file.
l
Project file—Select a Toad data compare project file.
l
Report file—Select a file location, file name, and file type for the export file.
l
Suffix—Select a suffix to append to the file name. The suffix can be the date and time that the file was generated or the content of a variable that you define with the Set
Variable system activity. See "Use System Automation
Activities" (page 79) for more information.
Visualize Data Open a Toad data visualization project, refresh the chart, and export contents as a PDF, HTML, image, Excel, RTF, or MHT.
l
Data Visualization document—Select a Toad data visualization file (.tdv).
l
Output file—Select a file location, file name, and file type for the export file.
l
Suffix—Select a suffix to append to the file name. The suffix can be the date and time that the file was generated or the content of a variable that you define with the Set
Variable system activity. See "Use System Automation
Activities" (page 79) for more information.
Notes: l
Status—Select Enabled to include the activity in script execution. Select
Disabled to disable the activity, for example, when testing other activities. Or right-click the activity in the design window and select/deselect Enabled.
l
Stop on Error—Allows you to select, for each activity, whether to stop or continue execution if Toad encounters an error.
l
Select the Log tab to review a script's execution log.
l
Automation does not support positional parameters denoted by a question mark.
78
Toad for Data Analysts User Guide
Automate
Use System Automation Activities
You can use the following activities in automation scripts.
Tip: You can save an activity and its properties as a template to reuse in other scripts. Rightclick the activity in the design window and select Save As Template. After you create the first template, a Templates toolbox displays.
Activity
Run Program
Set Variable
Description
Run a program with optional command-line arguments. Review the following for additional information: l
Program—Select a .bat or .exe file.
l
Arguments—Enter command-line arguments. You can also enter a variable, such as #sleep# in this field.
Note: If you want to run a macro in Access, enter
databasename /x macroname in this field. For example, if you have a macro that beeps and runs in your Northwind database, you would enter Northwind 2007.accdb /x beep. l
Run Directory—Select the directory to change to when running the program.
l
Return Code Variable—Enter a name for the return code variable. You can use this variable with the If..Condition
activity.
l
Verb—Enter verbs used when running the program, such as
"Print".
l
Wait for program to exit—Select this option to pause if there is an error. Select duration of wait time in minutes.
Note: If the script opens a command-line window, you must manually close the window once the script completes.
Add one or more variables to the script. When you execute the script,
Toad replaces the variable with the defined value. With this feature, you can update information that may be different each time you run the script, such as the department name, revenue, fiscal quarter, or product name.
Review the following for additional information:
Value—Select this option to specify a value for the variable or to build a variable expression. Click to build an expression. Build your expression by selecting from the list of variables, operators, and functions. (Click a list name in the left pane to display the items in the right pane. Double-click an item to add it.) Click Test to test the expression. See the following link for more information on VBScript functions: http://www.w3schools.com/VBscript/vbscript_ref_
79
Toad for Data Analysts User Guide
Automate
Activity
If..Condition
While..
Description functions.asp
SQL—Select or enter a variable value, you can enter a SQL statement to use as the variable. If you enter a statement, the value from the first row and column returned in the query is used as the variable value.
This is useful if you need a variable with a date.
See "Use Variables in Automation" (page 83) for more information.
Note: You can only use one variable per field or file name (a suffix counts as one variable for a file name).
Execute activities conditionally based on the value of a variable. For each condition you can define unique activities, such as connecting to a database, generating files, and sending emails.
To use this activity you must define a variable in the automation script with the Set Variable activity.
This activity can have one or more conditions. To delete a condition, select it and press DELETE. To add a condition, right-click the
If..Condition.. activity and select Add Branch. If you have multiple conditions, they do not have to be mutually exclusive. Multiple branches can be true.
l
Build condition expression—To define a condition, enter the variable name and expression in the expression field. Build your expression by selecting from the list of variables, operators, and functions. (Click a list name in the left pane to display the items in the right pane. Double-click an item to add it.) Click Test to test the expression. See the following link for more information on VBScript functions: http://www.w3schools.com/VBscript/vbscript_ref_functions.asp
Execute activities while the variable condition is true. The activity ends when the condition becomes false, or when it completes the selected number of loops.
To use this activity you must define a variable in the automation script with the Set Variable activity.
This activity can have one or more conditions. To delete a condition, select it and press DELETE. To add a condition, right-click the
If..Condition.. activity and select Add Branch. If you have multiple conditions, they do not have to be mutually exclusive. Multiple branches can be true.
Review the following for additional information: l
Build condition expression—To define a condition, enter the variable name and expression in the field. Build your expression by selecting from the list of variables, operators, and functions. (Click a list name in the left pane to display the
80
Toad for Data Analysts User Guide
Automate
Activity
Loop dataset
Description items in the right pane. Double-click an item to add it.) Click
Test to test the expression. See the following link for more information on VBScript functions: http://www.w3schools.com/VBscript/vbscript_ref_functions.asp
l
Loop—Enter the number of times to loop the activity. If the condition never becomes false, Toad ends the activity after this number. The default is 10.
Execute activities on each row of a data table. The data table must be the result set from an Execute Script activity that occurs previously in
the automation script. See "Use Database Automation Activities" (page
You can reference a column in the data table by setting the value of an initialized variable to 'DataTableName.ColumnName'. To initialize a variable, your script must have two different Set Variable activities.
The first Set Variable activity defines the variable value with a numeric value (such as 0 or 1.53), and the second defines it with the column variable name.
For example, assume you want to perform a set of activities on each of your company's products. You add the following activities and values: l
Execute Script—Execute a script that returns product IDs. You enter ProductIDTable in the Results variable field.
l
Set Variable—Add activity to give the variable an initial value.
You enter ID in the Name field and 0 in the Value field.
l
Loop dataset—Loop based on the dataset from the Execute
Script activity. You enter ProductIDTable in the Data Table field.
l
Set Variable—Add a second variable activity to reference the
Product_ID column in the data table. You enter ID in the Name field and ProductIDTable.Product_ID in the Value field. This redefines the values of the ID variable to the values in the
Product_ID column.
81
Toad for Data Analysts User Guide
Automate
Activity Description
82
Pause
See "Use Variables in Automation" (page 83) for more information on
a scenario that uses this activity.
Stops an activity for a set number of seconds before continuing. This is useful, for example, if you are using parallel activities and need to pause one branch while waiting for results or the complete execution of another branch.
Use this activity to group and organize two or more activities together.
Group
Activities
Parallel Run two or more activities in parallel. After adding a parallel activity to the design pane, you can right-click it to add additional branches for parallel activities.
Notes: l
Status—Select Enabled to include the activity in script execution. Select
Disabled to disable the activity, for example, when testing other activities. Or right-click the activity in the design window and select/deselect Enabled.
l
Stop on Error—Allows you to select, for each activity, whether to stop or continue execution if Toad encounters an error.
l
Select the Log tab to review a script's execution log.
l
Automation does not support positional parameters denoted by a question mark.
Toad for Data Analysts User Guide
Automate
Use Variables in Automation
Variables are a powerful feature that allow you to change data in your script or use a dataset collected from an activity in the automation script. For example, you can use variables to perform the following tasks: l
Send an email to a group of people where the list of recipients is automatically selected with a query.
l
Generate repetitive reports where only the product number, date, region, or other single element changes.
l
Customize file names by including a variable in the file name or automatically including the date that the automation script ran.
l
Find content in a file and replace it with the value of a variable.
Note: You must surround a variable name with the # sign (for example, #sleep#).
Generate Reports per Product
(Use the Loop Dataset Activity)
This scenario describes generating a report for each product, but you can use variables for a variety of reporting purposes: l
Report on warehouse inventory—query warehouse inventory with the inventory number as the variable, and then use the If..Condition.. activity to create different reports for items with no inventory, low inventory, and high inventory.
l
Report on revenue for each fiscal quarter—create a query with the fiscal quarter as the variable.
l
Report on revenue per sales person—create a query with the sales person's name or identification as the variable.
Scenario
Your Sales Manager wants a separate sales report for each of the company's products every week. He wants you to email the reports to him after they are generated.
To provide the reports to the Sales Manager, you need to create the product queries and the sales report. Then, you can use them in an automation script to run the queries, generate reports, and email the
Sales Manager every week.
To generate reports per product
1. Use the Query Builder to create a query that returns the product IDs.
2. Save the query and name it ProductIDQuery.tsm.
83
Toad for Data Analysts User Guide
Automate
84
3. Use the Query Builder to create a query that returns the sales information for products and enter the following search criteria in the specified columns:
Column
Product_ID
Order_Date
Search Criteria
Click in the Where Condition field. Select = and then Constant. Enter :ID in the field to define the variable.
Click in the Where Condition field. Select the Date
Range tab and then Last week.
4. Save the query and name it ProductSalesQuery.tsm.
5. Click Run Query and enter a value for the ID variable. The query results display.
6. Right-click the query results and select Send To | Data Report Designer.
7. Create the data report.
8. Save the report and name it ProductSalesPerWeek.tdr.
9. Close the report.
10. Click Automate to create a new automation script.
11. Click the Execute Script activity to add it to the Design pane and complete the following fields:
SQL file
Variable
Select ProductIDQuery.tsm.
Enter ProductIDTable.
12. Click the Set Variable activity and complete the following fields:
Name
Variable value
Enter ID.
Enter 0. Entering a number initializes the variable, which is required before you can redefine the value to another variable.
13. Click the Loop dataset activity and enter ProductIDTable in the Data Table field.
This loops activities on the content of the ProductIDQuery.tsm query.
14. Click the Set Variable activity to add a second variable and drag it into the Loop row.
15. Complete the following fields for the new Set Variable activity:
Name
Variable value
Enter ID.
Enter ProductIDTable.Product_ID. This uses the content of the Product_ID column in the
ProductIDTable table as the values for the variable.
Toad for Data Analysts User Guide
Automate
85
16. Click the Database Connection activity and drag it into the Loop row beneath the Set
Variable activity.
17. Click the Toad Report activity and drag it into the new Database Connection activity.
18. Complete the following fields in the Toad Report activity:
Report files
Export files
Select ProductSalesPerWeek.tdr.
Select the file location and enter SalesForProduct#ID# for the file name. When the automation script runs, it replaces #ID# with the variable value.
Note: You can only use one variable per field or file name (a suffix counts as one variable for a file name).
19. Click the Send Email activity and drag it beneath the Database Connection activity in the Loop row.
20. Enter the following information and then complete the remaining required fields for the Send Email activity:
To
Subject
Body
Add Attachments
Enter the Sales Manager's email address.
Enter Weekly sales report for product #ID#. When the automation script runs, it replaces #ID# with the variable value.
Enter the following: Attached is the weekly sales report for product #ID#. See the attached file.
Select the file created in the Toad Report activity and click Add.
21. Click Test to ensure that the script works. The following image displays the automation script in the Design pane:
Toad for Data Analysts User Guide
Automate
86
If ProductIDQuery.tsm returns five product IDs, Toad creates a report and sends an email for each one. If the first product ID is 101, the first email would have the following properties:
Toad for Data Analysts User Guide
Automate
Attachments
Subject
Body
SalesForProduct101.xls
Weekly sales report for product 101
Attached is the weekly sales report for product 101. See the attached file.
22. Save the automation script.
23. Schedule the automation script to run weekly. See "Execute Automation Scripts"
(page 90) for more information.
Find Unbatched Transactions
(Use the Row Count Field and If..Condition.. Activity)
Scenario
Your company has a web site that customers use to order products.
The orders are automatically batched, and each order is recorded as a row of data. When the batch is sent, it updates a column in the order row.
You need to run a daily report to find orders that were submitted but not batched. If there are any unbatched orders, you need to send an email to yourself with a list of the unbatched orders. If there are no unbatched orders, you need to send an email to yourself so you know that all orders were batched successfully.
To generate a daily report of unbatched orders
1. Save the query and name it UnbatchedOrders.tsm.
2. Click Automate to create a new automation script.
3. Click the Execute Script activity to add it to the Design pane and complete the following fields:
Row count variable
SQL file
Enter rc.
Select UnbatchedOrders.tsm.
4. Click the If..Condition.. activity.
5. Complete the following steps to define the first condition: a. Select the first condition and enter rc=0 in the Build condition
expression field.
b. Click the Send Email activity and drag it into the first condition.
c. Complete the required Send Email activity fields and enter No unbatched
orders in the Subject field.
87
Toad for Data Analysts User Guide
Automate
6. Complete the following steps to define the second condition: a. Select the second condition and enter rc>0 in the Build condition
expression field.
b. Click the Database Connection activity and drag it into the second condition.
c. Click the Select to File activity and drag it into the Database Connection activity in the second condition.
d. Complete the following Select to File activity fields:
SQL file
Export file
Select UnbatchedOrders.tsm.
Click the drop-down and complete the following: l
Excel file—Select this option, and then select the file location and enter
UnbatchedOrders_ for the file name.
l
Use column names for header row—Select this option and select a header row color.
l
Add Date/Time suffix to filename—Select this option and then select Date in the drop-down. This option appends the date the automation script ran to the file name.
e. Click the Send Email activity and drag it beneath the Select to File activity.
f. Enter the following information and then complete the remaining required fields for the Send Email activity:
Attachments
Subject
Body
Select the file created in the Select to File activity and click Add.
Enter #rc# unbatched order(s). When the automation script runs, it replaces #rc# with the variable value.
Enter the following: There were #rc# unbatched orders. See the attached file for more information.
7. Click Test to ensure that the script works. The following image displays the automation script in the Design pane:
88
Toad for Data Analysts User Guide
Automate
89
If there are no unbatched orders, Toad executes the first condition and sends an email with "No unbatched orders" in the subject . If there are unbatched orders, Toad executes the second condition. If there are two unbatched orders and you test on
December 10, 2009, the email would have the following properties:
Attachments
Subject
Body
UnbatchedOrders_2009-12-10.xls
2 unbatched orders
There were 2 unbatched orders. See the attached file for more information.
8. Save the automation script.
9. Schedule the automation script to run daily. See "Execute Automation Scripts" (page
Toad for Data Analysts User Guide
Automate
Execute Automation Scripts
You can execute automation scripts on demand from the Automation window or the
Project Manager. You can also schedule scripts to run on a recurring basis at a specific time. For example, schedule a script that performs long-running tasks to run when database activity is light.
To schedule an automation script
1. With a script open in Automation, click Schedule in the Wizard bar. A Windows
Scheduler task is created for the script and a task properties window displays. See
Schedule Windows Tasks for more information.
2. Select scheduling options in the Schedule tab of the task properties window.
3. After the script executes, to view the script's execution log, select View | Output or select the Log tab in the script's open Automation window.
Note: When you view the Toad Event Log in the Output window, all log content moves to that window. As a result, the log is cleared.
To execute a script from the Automation window
1. Click Test in the Wizard bar. The script is compiled and executes immediately.
2. To view the script's execution log, select the Log tab.
3. If you want to schedule the script, first resolve any problems that caused activities to fail or disable failed activities. An activity can be disabled from its Activity
Info window.
Tip: To execute a script from the Project Manager, right-click the script and select Execute.
90
Appendix: Contact Quest
Contact Quest Support
Quest Support is available to customers who have a trial version of a Quest product or who have purchased a Quest product and have a valid maintenance contract. Quest Support provides unlimited 24x7 access to SupportLink, our self-service portal. Visit SupportLink at http://support.quest.com
.
From SupportLink, you can do the following: l
Retrieve thousands of solutions from our online Knowledgebase l
Download the latest releases and service packs l
Create, update and review Support cases
View the Global Support Guide for a detailed explanation of support programs, online services, contact information, policies and procedures. The guide is available at: http://support.quest.com
.
Toad Community
Get the latest product information, find helpful resources, and join a discussion with the Toad for Data Analysts team and other community members. Join the Toad for Data Analysts community at http://tda.inside.quest.com/index.jspa
.
Contact Quest Software
Mail [email protected]
Quest Software, Inc.
World Headquarters
5 Polaris Way
Aliso Viejo, CA 92656
USA
Web site www.quest.com
See our web site for regional and international office information.
Toad for Data Analysts User Guide
Contact Quest Support
About Quest Software
Quest Software simplifies and reduces the cost of managing IT for more than 100,000 customers worldwide. Our innovative solutions make solving the toughest IT management problems easier, enabling customers to save time and money across physical, virtual and cloud environments. For more information about Quest go to www.quest.com
.
92
Index
A activities, automation automation database activities execute automation scripts file activities system activities variables
B build queries create cross-connection queries reverse engineer queries
C code automating shortcut keys view result sets connections create ODBC share for all session windows understand contact support cross-connection queries
D data browse parent tables compare differences
export in one click in result sets reports tutorial
Database Diagram tutorial
Database Explorer best method for locating objects
filter databases and objects search for objects database objects filter schemas object explorer search for databases automation activities
Diff Viewer, data
E
Editor reverse engineer queries shortcut keys
Excel add to Report Manager share linked queries export data with one click
F files automation activities
Toad for Data Analysts User Guide
Index filter databases and objects
H heterogeneous queries
I intellisense shortcut keys
K keyboard editor shortcuts
L linked queries
M
Master Detail Browser
O
Object Explorer filter databases and objects search for objects object search
ODBC create connections
One Click Export
P parameters in Automation
Q
Query Builder create cross-connection queries reverse engineer queries
tutorial
R reports data tutorial
DB2 manage reports
MySQL
ODBC
Oracle publish and share
SQLServer result sets reverse engineer queries
S script results scripts automating search database objects shortcut keys
SQL automating scripts shortcut keys
SQL Editor subqueries tutorial system automation activities
94
Toad for Data Analysts User Guide
Index
T tables browse data in related tutorials
automate queries and email reports 64
create database diagrams
create ODBC connections create Toad data reports subquery visually build queries variables in Automation
V
95
Stiahnuť
Reklama