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-21
Using Expressions to Calculate Report Values
The PARTSUPP table contains rows that record a part number, the supplier number,
the part cost, and the quantity received. If the supplier changes the cost of a part, more
than one row of the PARTSUPP might describe the same part number and supplier. If
you want to count the number of distinct suppliers of each part, you can use the
following query:
>> SELECT PARTNUM, COUNT ( DISTINCT SUPPNUM )
+> FROM INVENT.PARTSUPP
+> GROUP BY PARTNUM;
S> LIST NEXT 2;
PARTNUM (EXPR)
------- ----------------------
212 2
244 2
S>
The next query counts the number of orders taken by each sales representative who
has more than one customer with current orders:
>> SELECT SALESREP, COUNT (DISTINCT ORDERNUM)
+> FROM SALES.ORDERS OX
+> GROUP BY SALESREP
+> HAVING EXISTS (SELECT SALESREP
+> FROM SALES.ORDERS
+> WHERE OX.SALESREP = SALESREP
+> AND COUNT (DISTINCT CUSTNUM) > 1
+> GROUP BY SALESREP);
SALESREP (EXPR)
-------- -------------------
220 3
226 3
If you specify DISTINCT preceding the select list, you cannot specify it in any
aggregate function in the select list or in any predicate of the WHERE or HAVING
clause.
Using Expressions to Calculate Report Values
You can calculate values for items in a report output line. If you are printing the report
in the default report format, you specify the calculation in the select list.
The query in Figure 3-5 includes two expressions in the select list. The first expression
calculates the total part cost for the available quantity of each part. The second
expression calculates the profit (price minus cost) for the available quantity of each
part.