Query a database using Interactive SQL

Using the SQL SELECT statement and Interactive SQL, you can query a database on another iSeries™ server for data you need to create or update a table on the local server.

The SELECT statement allows you to specify the table name and columns containing the desired data, and selection criteria or filters that determine which rows of data are retrieved. If the SELECT statement is successful, the result is one or more rows of the specified table.

In addition to getting data from one table, SQL allows you to get information from columns contained in two or more tables in the same database by using a join operation. If the SELECT statement is successful, the result is one or more rows of the specified tables. The data values in the columns of the rows returned represent a composite of the data values contained in specified tables.

Using an Interactive SQL query, the results of a query can be placed in a database file on the local server. If a commitment control level is specified for the Interactive SQL process, it applies to the application server (AS); the database file on the local server is under a commitment control level of *NONE.

Interactive SQL allows you to do the following things:

Consider the situation in which the KC105 dealership is transferring its entire stock of part number 1234567 to KC110. KC110 queries the KC105 database for the part they acquire from KC105. The result of this inventory query is returned to a database file that already exists on the KC110 server. This is the process you can use to complete this task:

Use the Start SQL (STRSQL) command to get the Interactive SQL display. Before you enter any SQL statement (other than a CONNECT) for the new database, specify that the results of this operation are sent to a database file on the local server by doing the following steps:

  1. Select the Services option from the Enter SQL Statements display.
  2. Select the Change Session Attributes option from the Services display.
  3. Enter the Select Output Device option from the Session Attributes Display.
  4. Type a 3 for a database file in the Output device field and press Enter. The following display is shown:
    Change File
     
    Type choices, press Enter.
     
    File . . . . . . . . .   QSQLSELECT   Name
    Library  . . . . . .   QGPL         Name
    Member . . . . . . . .   *FILE        Name, *FILE, *FIRST
     
    Option . . . . . . . .   1            1=Create new file
    2=Replace file
    3=Create new member
    4=Replace member
    5=Add to member
     
    For a new file:
    Authority  . . . . .   *LIBCRTAUT   *LIBCRTAUT, *CHANGE, *ALL
    *EXCLUDE, *USE
    authorization list name
     
    Text . . . . . . . .
     
     
    F3=Exit     F5=Refresh     F12=Cancel
     
  5. Specify the name of the database file that is to receive the results.

When the database name is specified, you can begin your Interactive SQL processing as shown in the following example.

Enter SQL Statements
 
Type SQL statement, press Enter.
Current connection is to relational database KC000.
CONNECT TO KC105__________________________________________________________
Current connection is to relational database KC105.
====> SELECT * FROM INVENTORY_____________________________________________
WHERE PART = '1234567'____________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
Bottom
F3=Exit   F4=Prompt   F6=Insert line   F9=Retrieve   F10=Copy line
F12=Cancel            F13=Services     F24=More keys
 
Related concepts
SQL programming
Related reference
SQL reference