24
Tue, Dec
1 New Articles

Putting Run SQL Scripts to Work for You

SQL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Execute a script that contains a single SQL statement, multiple SQL statements, or even CL commands!

By Skip Marchesani

Several years ago, I began using what is now called the Run SQL Scripts function (also known as the SQL Script Center or Script Center in iSeries Navigator or System i Navigator, respectively) to demonstrate various SQL functions and to answer SQL syntax and function questions when I teach SQL-related topics. Now that the SQL Script Center is becoming more widely known and used, when I teach and use it for demonstrations, I am getting more and more questions about how it works.

 

One reason for the increasing number of questions is that there is little information available for Run SQL Scripts via IBM's System i Information Center Web site, and IBM has no softcopy publication available for it. The only documentation available is Help, which has improved over time but on occasion can still be a challenge when you're trying to find an answer to a question. So based on the more frequently asked questions I get while teaching, here are some Script Center tips.

Opening Run SQL Scripts

In case someone reading this is unfamiliar with Run SQL Scripts in iSeries Navigator or System i Navigator, it is part of the Database function, so therefore you must have the Database function installed to use Run SQL Scripts. It can be said that in part it is the PC replacement for Interactive SQL (the STRSQL command) on the green-screen side of the System i. Run SQL Scripts and Interactive SQL do overlap in function, but each can do things that the other cannot.

 

To open Run SQL Scripts, expand the Database function (click on the + next to Database) and then right-click on the database name, which will appear immediately below the Database function. The Run SQL Scripts function then appears in three places: near the bottom of the resulting pop-up menu, as an option in the File drop-down menu in the toolbar at the top of the panel, and as an option under Database Tasks in the lower pane at the bottom of the panel. Clicking on any of these three options will open the Run SQL Scripts panel.

What Can the SQL Script Center Do?

The SQL Script Center allows the user to execute a script that contains a single SQL statement or multiple SQL statements. If the script contains multiple SQL statements, the user can execute the entire script in three ways: by starting with the first statement in the script and ending with the last statement in the script, by choosing the currently selected or highlighted statement or statements (the statement where the cursor is currently positioned), or by selecting a subset of the script, starting with the currently selected statement and ending with the last statement in the script. The drop-down menu for Run in the toolbar at the top of the panel shows these options as All, Selected, or From Selected. There is also an hourglass-shaped icon for each of these options immediately below the toolbar.

Executing SQL Statements and CL Commands

Did you notice in the previous paragraph that I started out using the words "SQL statements" and ended by just using the word "statement" without prefacing it with "SQL"? There is a method to my madness. Since this is the SQL Script Center we are discussing, it is obviously going to be able to execute SQL statements. What isn't obvious, and users are delighted to discover, is that it can also execute any Control Language (CL) command that can be executed in a batch program. Therefore, to refine my earlier definition, the SQL Script Center allows the user to execute a script that contains a single SQL statement or CL command or multiple SQL statements and/or CL commands. This gives the SQL Script Center significantly enhanced function compared to what you get with the RUNSQLSTM command.

 

An SQL statement or a CL command is entered on the upper portion of the Input pane of the Run SQL Scripts window. SQL statements are entered as is, without any prefix. CL commands must be prefaced with CL: (not case-sensitive). Each SQL statement and/or CL command to be executed by the SQL Script Center must end with a semi-colon (;).

 

The nice thing about the SQL Script Center is that once a script has been created (a script is a collection of one or more SQL statements and/or CL commands), it can be stored as a PC file with a .SQL extension, on a PC, or in the System i IFS. This file that contains the script can then be accessed and reopened by the SQL Script Center at a future date and the SQL statements and/or CL commands in the script re-executed.

Changing Font Size for the Input Pane

When entering statements in the Input pane, the default font is hard to read if displayed using an LCD projector for teaching purposes. And if your eyes are going through the aging process (like mine), the default font may be hard to read on your PC display. Again, users are pleasantly surprised to find that they can change the font type and increase the font size for the Input pane to make it easier to read. Just click on View in the toolbar, and then click on Font in the resulting drop-down menu. I find that an 18-point font works well when displaying the Input panel using an LCD projector.

Viewing Completion Messages and Results Sets

The lower portion of the window is the Output pane. There will always be 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, there will be a Results tab that displays the results set for the SELECT statement.  

Displaying Multiple Results Sets Windows

The issue that many users have with the Results tab is that it displays only the results set for the last SELECT statement executed, and many times you want to see the results set for a series of SELECT statements so they can be compared. Again, this is very easy to do: Just click on Options in the toolbar and then click on Display Results in a Separate Window to select it. Make sure that Smart Statement Selection is selected (normally, it should be selected since it's the default). With these options selected, two or more SELECT statements can be executed, and the results set for each will be displayed in a separate window.

 

The window for one results set is displayed directly on top of the window for the other, so you have to manually reposition and possibly resize all displayed windows to be able to see each one and make visual comparisons. The down side of Display Results in a Separate Window is that each open window must be manually closed to remove it from your desktop; however, I feel that this is a minor inconvenience compared to the benefit of having multiple results sets displayed at the same time.

Executing Multiple SQL Statements and/or CL Commands

To execute two or more SELECT statements (or other SQL statements or CL commands), there are a couple of options. You can highlight each SELECT statement one at a time by placing the cursor on the statement and then selecting Run Selected either in the drop-down menu for Run in the toolbar or by clicking the appropriate icon for Run Selected directly underneath the toolbar.

 

Two or more SQL statements can also be executed without having to select each one. First, as mentioned previously, make sure Display Results in a Separate Window is selected from the Options drop-down menu on the toolbar. Then highlight each SQL statement to be executed and move the cursor to select Run Selected as described in the previous paragraph.

 

Each of these two options requires that the statement or statements be selected and then the cursor moved to the appropriate execution option on the tool bar.

 

The third option available for executing an SQL statement in the Options drop-down menu on the toolbar eliminates selecting the statement and then selecting the execution option. This option is the one that I prefer to use when teaching. If you select Run Statement on Double-Click from this drop-down menu, you can execute any single SQL or CL statement by placing the cursor on the statement and double-clicking it with your mouse. This allows you to easily execute a series of SQL statements and/or CL commands—one at a time—and, if it's a SELECT statement, have each results set displayed in a separate window. And you don't have to keep moving the cursor between the statements and the toolbar.

Prompting SQL Statement Creation

One question that is asked on a very frequent basis is whether the SQL Script Center has an SQL statement prompter like the one available with Interactive SQL. The answer is like the Hertz commercial: Not exactly. However, this "not exactly" is used in a more positive context than the one from the Hertz commercial.

 

Interactive SQL provides a good multilevel SQL prompter that works with a subset of the SQL statements available in DB2. The SQL Script Center does not have this type of SQL prompting. It instead takes a different approach called "SQL Assist," which provides an easy-to-use, graphical approach to creating a SELECT, INSERT, UPDATE, or DELETE statement. These four SQL statements are the ones that are used a very large percentage of the time. To invoke SQL Assist, press F4 with the cursor placed anywhere on the Input panel, or click on Edit from the toolbar and select SQL Assist from the drop-down menu. Either option takes you to the primary SQL Assist panel.

A Powerful and Flexible Tool

The Run SQL Scripts function (a.k.a. the SQL Script Center or Script Center ) is iSeries Navigator's or System i Navigator's answer to Interactive SQL on the green-screen side of the System i. It is an extremely powerful and flexible tool with lots of functionality that can have a very positive impact on application developer productivity. However, finding out all the neat things it can do can be a challenge because the only documentation is in the Help. Spend some time with the SQL Script Center and play with it. Try the tips that I've outlined in this article and explore the many other toolbar options that I have not discussed and you will uncover lots of good things you can do with it. If you find something exciting and interesting that I've not discussed, please mention it in the forums discussion associated with this article. Or tell me about it in an email note, and maybe I'll include it in my next article.
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: