• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Configuring Run SQL Scripts for Ad Hoc Queries

    June 10, 2009 Skip Marchesani

    Many months ago, when I needed to create and execute an ad hoc query using SQL, my tool of choice was Interactive SQL, available via the System i green screen interface. I don’t recall any dramatic change taking place–I suspect it was gradual–but these days I find myself using Run SQL Scripts (a.k.a. SQL Script Center or Script Center) from System i Navigator, instead of Interactive SQL, to execute an ad hoc SQL Query.

    The Script Center offers a couple of advantages over Interactive SQL. Specifically the Script Center allows you to intermix and execute SQL statements and batch CL commands, store one or more SQL statements and/or batch CL commands as a script for later retrieval and execution, include text or comments for documentation (not that we programmers would ever need to document anything), and display multiple result sets from the execution of multiple SQL SELECT statements.

    One thing the Script Center cannot do (which Interactive SQL can do) is provide multi-level prompting for SQL statements. However, these days I’m pretty comfortable with SQL syntax and don’t need to lean on SQL statement prompting as much as I used to.

    One frustration that I hear is that the script center is not the best tool for ad hoc SQL queries.

    My answer to that is if you attempt to create and execute ad hoc SQL queries with the Script Center using the default configuration or setup options, you may find yourself frustrated–just as I was when I first started to use it. The good news is it’s fairly easy to tweak the default options and optimize the Script Center for ad hoc SQL Queries.

    Figure 1.

    Viewing Completion Messages and Results Sets

    Before we discuss any tweaking, let’s take a quick look at the Output Pane in the lower portion of the Run SQL Scripts window. The Output pane will always have a Messages tab where a completion message is displayed for each SQL statement or CL command that is executed. And when a SELECT statement is executed with the default options, there will also be a tab to the right of the Messages tab that displays the results set for the SELECT statement, as shown in Figure 1.

    Choosing the Correct Options

    The results tab does not lend itself to ad hoc SQL queries with complex results sets and is limited in function. If you want to do ad hoc SQL queries, and execute multiple SQL statements and/or batch CL commands and display multiple result sets, you need to tweak the Script Center by changing the Script Center run time options.

    Figure 2.

    To make any changes, click on Options in the toolbar, then select “Display Results in a Separate Window,” and “Run Statements on Double Click.” Also make sure that “Stop on Error” and “Smart Statement Selection” are selected, as shown in Figure 2. Normally they would be selected since they are the default. With these options selected, multiple SELECT statements (and/or multiple batch CL commands) can be executed, and the results set for SELECT statements will be displayed in a separate window.

    A detailed discussion along with examples of the above changes is available in my article, Displaying Multiple Results Sets in Run SQL Scripts.

    Make It Easy On Your Eyes

    The next tweak is optional, but if you’re like me and find your eyes are aging along with the rest of your body, you may want to increase the font size of text displayed in the Run SQL Scripts window. To change the font size, click on View in the toolbar at the top left of the Run SQL Scripts window and then click on Font.

    Figure 3.

    Next select the desired font and size in the resulting Font pop up window, as shown in Figure 3. Note that the default font and size is Tahoma 12, and the font and size used in the figures for this article is Tahoma 18. It’s also worth noting that in V5R4 a font change only affects the text in the Run SQL Scripts window, while in V6R1 a font change affects both the text in the Run SQL Scripts window and the information displayed in the result set window.

    Changing JDBC Setup Connection Options

    The final tweaks that you may want to make for ad hoc SQL queries are to set up your default SQL library and library list, select either SQL or System object naming convention, and make sure the displayed information in your result set is translated correctly.

    Figure 4.

    These options are changed in the JDBC Setup window, which is displayed by clicking on Connection in the toolbar and then JDBC Setup in the drop-down, as shown in Figure 4.

    Figure 5.

    When the JDBC Setup window opens, by default the Server tab is displayed as shown in Figure 5. The Server tab allows you to specify an SQL Default Library (current library for Script Center) and library list to be used for the execution of any SQL statement or batch CL command.

    Figure 6.

    To select the object naming convention for the Script Center, click on the Format tab in the JDBC Setup window. “Naming Convention” is at the top left and SQL (library.object) or System (library/object) can be selected as shown in Figure 6. Most likely you will select “System,” unless you are creating SQL statements to be used on database platforms other than DB2 for System i.

    A detailed discussion along with examples for SQL Default Library, Library List, and object Naming Convention is available in my article, Changing the Library List for Run SQL Scripts.

    There’s Hexadecimal Data In My Result Set!

    Have you ever run an SQL query and wound up with hexadecimal data in the result set? The first time it happened to me, I wanted to know why it happened and how I could fix it.

    To make a long story short, this can occur when you derive or create a new column on the fly in your SELECT statement. That new column is a combination of data from one or more character and numeric columns, and as a result of combining the data, it’s not translated correctly when displayed on your PC. Fortunately, it’s easy to fix.

    Figure 7.

    To correctly translate the combined character and numeric data, click on the Translation tab in the JDBC Setup window, then select Translate CCSID 65535, as shown in Figure 7. Selecting this option will ensure that the correct code page is used to translate the data when it’s displayed on your PC.

    Skip Marchesani retired from IBM after 30 years and is now a consultant with Custom Systems Corporation. He is also a founding partner of System i Developer and the RPG & DB2 Summit. Skip spent much of his IBM career working with the Rochester Development Lab on projects for S/38 and AS/400 and was involved with the development of the AS/400. He was part of the team that taught early AS/400 education to customers and IBM lab sites worldwide. Skip is recognized as an industry expert on DB2 for i and the author of the book DB2/400: The New AS/400 Database. He specializes in providing customized education for any area of the System i, iSeries, and AS/400; does database design and design reviews; and performs general System i, iSeries, and AS/400 consulting for interested clients. He has been a speaker for user groups, technical conferences, and System i, iSeries, and AS/400 audiences around the world. He is an award-winning COMMON speaker and has received its Distinguished Service Award. Send your questions or comments for Skip to Ted Holt via the IT Jungle Contact page.

    RELATED STORIES

    Displaying Multiple Results Sets in Run SQL Scripts

    Changing the Library List for Run SQL Scripts



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Raz-Lee Security

    Start your Road to Zero Trust!

    Firewall Network security, controlling Exit Points, Open DB’s and SSH. Rule Wizards and graphical BI.

    Request Demo

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Vision Solutions:  New white paper! Review the full range of Data Protection & Recovery options.
    BCD:  View the WebSmart PHP YouTube demo direct from the COMMON Expo floor - Free Trial !
    Cosyn:  Get a BI 'Proof of Concept' using your own data

    IT Jungle Store Top Book Picks

    Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
    The System i Pocket RPG & RPG IV Guide: List Price, $69.95
    The iSeries Pocket Database Guide: List Price, $59.00
    The iSeries Pocket SQL Guide: List Price, $59.00
    The iSeries Pocket Query Guide: List Price, $49.00
    The iSeries Pocket WebFacing Primer: List Price, $39.00
    Migrating to WebSphere Express for iSeries: List Price, $49.00
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00
    Can the AS/400 Survive IBM?: List Price, $49.00
    Chip Wars: List Price, $29.95

    Application Modernization is Top Software Priority, Forrester Says Infrastructure Business Monopoly

    Leave a Reply Cancel reply

Volume 9, Number 19 -- June 10, 2009
THIS ISSUE SPONSORED BY:

Help/Systems
WorksRight Software
Guild Companies

Table of Contents

  • Configuring Run SQL Scripts for Ad Hoc Queries
  • Advanced DB2 for i Data Access Techniques with .NET
  • Taking Care of PC5250 Popup Keypad Problems

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle