SQL/MP Report Writer Guide
Table Of Contents
- What’s New in This Manual
- About This Manual
- 1 Introduction to the NonStop SQL/MP Report Writer
- 2 Using SQLCI and the Report Writer
- 3 Selecting Data for a Report
- 4 Customizing a Report
- Defining the Layout
- Specifying the Items in a Detail Line
- Naming Select List and Detail Line Items
- Organizing Rows Into Break Groups
- Labeling Information
- Formatting Data Values
- Formatting Dates and Times
- Using TACL to Pass Parameters
- Conditional Printing of Items or Line Entries
- Redefining Special Characters
- Calculating Totals
- Calculating Subtotals
- Printing Double-Byte Characters
- A Comparison of the Report Writer and the Enform Language
- Index
Selecting Data for a Report
HP NonStop SQL/MP Report Writer Guide—527213-001
3-30
Using Subqueries
The following specification uses an implicit correlation name to achieve the same result
as the preceding query:
>> SELECT SUPPNUM, PARTNUM, PARTCOST
+> FROM INVENT.PARTSUPP
+> WHERE PARTCOST > (SELECT AVG(PARTCOST)
+> FROM INVENT.PARTSUPP P
+> WHERE PARTSUPP.PARTNUM = P.PARTNUM)
+> ORDER BY SUPPNUM;
Defining explicit correlation names provides clearer documentation of what the query
does.
You can use quantified predicates for selecting rows in relation to all or any of the rows
selected by a different search condition. For example, you can select PARTSUPP table
rows that contain a part cost greater than the suggested price for the part in the
PARTS table:
>> SELECT *
+> FROM PARTSUPP PS
+> WHERE PARTCOST > ANY (SELECT PRICE
+> FROM SALES.PARTS
+> WHERE PARTS.PARTNUM = PS.PARTNUM);
S> LIST NEXT 5;
PARTNUM SUPPNUM PARTCOST QTY_RECEIVED
------- ------- ------------ ------------
212 6 3000.00 2
***WARNING from SQLCI[10098] There are no more selected rows.
S>
The quantified predicate is evaluated for each row selected by the outer query. The
subquery selects the PARTCOST from the PARTS table for the part with the same
number as the current row of the outer query. Only one part qualifies for selection.
In the next example, the subquery sums the quantity ordered of each part retrieved in
the outer query. The main query selects parts for which the quantity on order is greater
than or equal to a specified percent of the parts available. The query allows you to
enter the percent as a parameter each time you execute the query. The query is in an
command file named ORDERPCT.