Example of using basic SELECT prototyping
We'll use an example to show how to use basic SELECT prototyping to build a SELECT statement and then run it to see the results.
- Department is not
E01
, and - JOB is
Manager
or SALARY is at least $40,000
- LASTNAME
- FIRSTNME
- WORKDEPT
- JOB
- SALARY (in ascending sequence)
- BONUS
You can specify details on the secondary Basic SELECT Prototyping panel for more than one column at a time. However, for the purpose of clarity, the following steps show the details being entered one at a time for each column, and the resultant SELECT statement that FM/Db2 progressively builds (and displays at the top of the panel) after you press Enter.
Step 1
S
in the S entry
field: S LOp ( Tab Column Name Data Type(length) Op Value ) ⋮ s ___ _ #1 LASTNAME VARCHAR(15) _____________________ _ ⋮
- Adding the name of the selected column (LASTNAME) to the SELECT clause.
SELECT #1.LASTNAME FROM DSN8810.EMP #1, DSN8810.EEMP #2 WHERE ? ORDER BY ?
Step 2
S
in the S entry
field: S LOp ( Tab Column Name Data Type(length) Op Value ) ⋮ s ___ _ #1 FIRSTNME VARCHAR(12) _____________________ _ ⋮
- Adding the name of the selected column (FIRSTNME) to the SELECT clause.
SELECT #1.LASTNAME, #1.FIRSTNME FROM DSN8810.EMP #1, DSN8810.EEMP #2 WHERE ? STNAME <> 'SMITH' ORDER BY ?
Step 3
- Select the column, WORKDEPT, by typing
S
in the S entry field, - Type the expression operator
<>
in the Op entry field, and - Type
E01
in the Value entry field:
S LOp ( Tab Column Name Data Type(length) Op Value ) ⋮ s ___ _ #1 WORKDEPT CHAR(3) <> e01__________________ _ ⋮
- Adding the name of the selected column (WORKDEPT) to the SELECT clause.
- Adding a predicate,
#1.WORKDEPT <> 'E01'
, to the WHERE clause.
SELECT #1.LASTNAME, #1.FIRSTNME, #1.WORKDEPT FROM DSN8810.EMP #1, DSN8810.EEMP #2 WHERE #1.WORKDEPT <> 'E01' ORDER BY ?
Step 4
- Select the column, JOB, by typing
S
in the S entry field, - Type an opening parenthesis,
(
, in the ( entry field, and - Type
MANAGER
in the Value entry field:
S LOp ( Tab Column Name Data Type(length) Op Value ) ⋮ s ___ ( #1 JOB CHAR(8) manager______________ _ ⋮
- Adding the name of the selected column (JOB) to the SELECT clause.
- Inserting the default logical operator
AND
before adding a predicate,(#1.JOB = 'MANAGER'
, to the WHERE clause.
SELECT #1.LASTNAME, #1.FIRSTNME, #1.WORKDEPT, #1.JOB FROM DSN8810.EMP #1, DSN8810.EEMP #2 WHERE #1.WORKDEPT <> 'E01' AND (#1.JOB = 'MANAGER' ORDER BY ?
Step 5
- Select the column, SALARY, for ascending sequence by typing
A
in the S entry field, - Type the logical operator,
OR
, in the LOp entry field, - Type the expression operator
>=
in the Op entry field, and - Type
40000
in the Value entry field. - Type a closing parenthesis in the ) entry field:
S LOp ( Tab Column Name Data Type(length) Op Value ) ⋮ a or_ _ #1 SALARY DECIMAL(9,2) >= 40000________________ ) ⋮
- Adding the name of the selected column (SALARY) to the SELECT clause.
- Adding a predicate,
OR #1.SALARY >= 40000)
, to the WHERE clause. - Adding the name of the selected column (SALARY), and the keyword
ASC
, to the ORDER BY clause.
SELECT #1.LASTNAME, #1.FIRSTNME, #1.WORKDEPT, #1.JOB, #1.SALARY FROM DSN8810.EMP #1, DSN8810.EEMP #2 WHERE #1.WORKDEPT <> 'E01' AND (#1.JOB = 'MANAGER' OR #1.SALARY >= 40000) ORDER BY #1.SALARY ASC
Step 6
S
in
the S entry field: S LOp ( Tab Column Name Data Type(length) Op Value ) ⋮ s ___ _ #2 BONUS DECIMAL(9,2) _____________________ _ ⋮
- Adding the name of the selected column (BONUS) to the SELECT clause.
SELECT #1.LASTNAME, #1.FIRSTNME, #1.WORKDEPT, #1.JOB, #1.SALARY, #2.BONUS FROM DSN8810.EMP #1, DSN8810.EEMP #2 WHERE #1.WORKDEPT <> 'E01' AND (#1.JOB = 'MANAGER' OR #1.SALARY >= 40000) ORDER BY #1.SALARY ASC
Details entered together on the secondary Basic SELECT Prototyping panel shows how the Basic SELECT Prototyping panel is displayed if you had entered the details for all of the columns at the same time.
For example, if you enter the details as shown in Details entered together on the secondary Basic SELECT Prototyping panel, FIRSTNME is shown before LASTNAME in the generated SELECT statement.
Related tasks
Related references