SQL aggregate functions supported for COBOL
SQL aggregate functions are supported for COBOL and .NET applications (by using IMS Enterprise Suite IMS Data Provider for Microsoft .NET).
- AVG
- COUNT
- MAX
- MIN
- SUM
- ORDER BY
- ASC
- DESC
- GROUP BY
The following table shows the data types of the fields that are accepted by the aggregate functions, along with the resulting data type in the ResultSet.
Function | Argument types | Results and result types |
---|---|---|
AVG | All supported numeric data types for SQL statements in COBOL programs are supported, including TINYINT, SMALLINT, INTEGER, BIGINT, Zoned Decimal, and Packed Decimal |
|
COUNT | Any supported data type |
|
MAX | TINYINT, INTEGER, BIGINT, Zoned Decimal, Packed Decimal, CHAR, BINARY, DATE, TIME, and TIMESTAMP |
|
MIN | TINYINT, INTEGER, BIGINT, Zoned Decimal, Packed Decimal, CHAR, BINARY, DATE, TIME, and TIMESTAMP |
|
SUM | All supported numeric data types for SQL statements in COBOL programs are supported, including TINYINT, SMALLINT, INTEGER, BIGINT, Zoned Decimal and Packed Decimal |
|
Column names generated by aggregate functions
The generated column name
from an aggregate function is a combination of the aggregate function name and the field name,
separated by an underscore character (_). For example, the statement SELECT
MAX(age)
results in a column name MAX_age.
If the aggregate function argument field
is table-qualified, the generated column name is the combination of the aggregate function name, the
table name, and the column name, separated by underscore characters (_). For example, SELECT
MAX(Employee.age)
results in a column name MAX_Employee_age.
The aggregate function is executed first, and then the required number of rows of result are fetched from the result set.
Using the ORDER BY and GROUP BY clauses
The field names that are specified in a GROUP BY or ORDER BY clause must match exactly the field name that is specified in the SELECT statement. In order to GROUP BY properly, the fields specified in SELECT list must also be specified in the GROUP BY list.
SELECT HOSPNAME, COUNT(PATNAME) FROM PCB01.HOSPITAL, PATIENT GROUP BY HOSPNAME
ORDER BY HOSPNAME