Hello, you are not logged in.  Login or sign up
Toad on Twitter Follow Toad Search Toad World Search
Blogger List   

All Recent Blog Entries
 

Johannes Ahrends
Unicode and Toad

Ben Boise
Toad SC Discussions

Kevin Dalton
Benchmark Factory

Steven Feuerstein
PL/SQL Obsession

Devin Gallagher
Toad SC discussions

Stuart Hodgins
JProbe Discussions

  Henrik "Mauritz" Johnson
Toad Tips & Tricks on the "other" Toads
  Mark Kurtz
Toad SC discussions
  Michael Lumbard
Toad SC discussions
Daniel Norwood
Toad for Data Analysts,
Toad Extension for Visual Studio
Debbie Peabody
Toad for Data Analysts
Gary Piper
Toad Reports Manager
John Pocknell
Toad for Oracle, JProbe
Kuljit Sangha
Toad SC discussions
Bert Scalzo Indicates Oracle ACE status
Toad for Oracle, Data Modeling, Benchmarking
Jeff Smith
Toad product family
Richard To
SQL Optimization
Jim Wankowski
DB2 - LUW and z/OS
John Weathington
  Toad World Editor
Toad World issues

  Toad Data Modeler Opens in a new window
Data Modeling
 
  Real Automated Code Testing for Oracle
Quest Code Tester blog

Blogs
Toad and Database Commentaries

Toad World blogs are a mix of insightful how-tos from Quest experts as well as their commentary on experiences with new database technologies.  Have some views of your own to share?  Post your comments!  Note:  Comments are restricted to registered Toad World users.

Do you have a topic that you'd like discussed?  We'd love to hear from you.  Send us your idea for a blog topic.

Automation – Exception Reports (Using the Row Count variable)
 
Location: Blogs Debbie Peabody's blog    
 Debbie Peabody 1/20/2010 10:05 AM

 

 

Not all reports are repetitive. Perhaps you have a situation where you only want to produce a report when a set of circumstances arise.

 
Here is a simple example. Clerks enter orders and at the end of the day submit the batch of orders for processing. If they forgot to submit a batch of orders a manager would want to know this and resolve quickly. The time a batch is submitted is stored in a submitted_date column. A select statement looking for null values in this column would give you one or more rows when this exception occurred.
 

So how could we automate this query and only send an email to the manager when a clerk did not submit their orders? To accomplish this task we are going to use the Row Count variable and If Condition Activity.

 

What’s the Row Count Variable?

Any of the activities that execute a select statement have a built in automation variable called Row Count. (That would be these 4 automation activities; Select to File, Execute Script, Toad Report, and Toad Pivot Grid.)

 

To use this variable just enter a name. When the activity executes your Sql it will set the number of rows returned.

 

 

 

This value can now be used with the If..Condition activity. Add an expression that will define your exception condition. For example, if RC > 0 send email to manager.

 

 

 

Putting the Row Count to Work

  

Let’s walk through an example. You can follow along with this example if you download this zip file. You need to unzip the files in ‘C:\Temp’ unless you want to change some paths.

1)    Start Toad for Data Analysis and create a new Excel connection to the Orders.xls file. (Use File | New Connection. Pick Excel from the group type and browse to the file. Press Select to connect.) I’m using Excel as my database.

 

 

2)    Next, I need to build my exception query. Open OrdersException.tsm from the sample files. This is a Query builder file where I select from the orders table looking for rows where the submitted_date is null. Run the query to ensure everything is set up correctly. You should get 3 rows.

3)    Now let’s build the automation script. (You can open the sample Script_ExceptionReporting.tas or build one yourself following these steps.) Open the automation window and add a ‘Select To File’ activity. Enter RC as the name of the Row Count variable. Browse to the OrdersException.tsm file to set the SQL Script. Choose to export to an Excel file named OrdersNotSubmitted.xls.

4)    Select the If..Condition activity from the toolbox. Double click on the first Condition and enter RC>0. (There is an expression builder that can be used for more complicated condition expressions.) Go ahead and delete the right side condition as we aren’t going to use it. To do this, select the condition, right click and delete.

5)    Now add the activity you want to perform when the condition is met. An email is the usual activity but for this example I am adding a Log Comment Activity. Here I just want to dereference the variable to the output window so I can confirm the condition is working. In the comment enter ‘Better Send an email. Rows returned were #RC#’. The pound signs ‘#’ dereferences the content of the RC variable.
 

6)    Now we are ready to roll. Click ‘test’ and in the output window you can confirm the number of rows retrieved and the condition result. To view the rows exported click on the file name in the output window. It will open Excel to view the rows.

So there is your automated exception report. Adapt this to your needs. If you have any questions on using this please post them on the Toad for Data Analysts Community.
 
Have fun!
Debbie

 

 

Permalink |  Trackback

Comment:
Add Comment   Cancel 
Search Blog Entries
 
Copyright 2010 by Quest Software  | Terms Of Use | Privacy Statement | Contact Us