Start of change

-20117   A WINDOW SPECIFICATION FOR AN OLAP SPECIFICATION IS NOT VALID. REASON CODE = reason-code.

Explanation

The window specification (OVER clause) of an OLAP specification invocation is not correctly specified.

reason-code
The incorrect specification:
1
RANGE or ROWS is specified without an ORDER BY clause in the window specification.
2
RANGE is specified and the ORDER BY clause in the window specification includes more than one sort key expression.
3
RANGE is specified and the data type of the range value cannot be used in a subtraction expression with the data type of the sort key expression in the ORDER BY clause in the window specification.

System action

The statement cannot be processed.

Programmer response

Take the action that corresponds to the reason-code value:

For reason-code:
1
Add a window ORDER BY clause to each window specification that specifies RANGE or ROWS.
2
Ensure that each window specification that includes RANGE has exactly one sort key expression in the window ORDER BY clause.
3
For each window specification that includes RANGE, ensure that the range value can be subtracted from the sort key expression in the window ORDER BY clause, which must be a numeric type or datetime type. For datetime sort key expressions, the range value must be the specific datetime duration decimal type with the correct precision and scale.

SQLSTATE

428EZ

End of change