I have a SQL Cursor called by a program something like this
EXEC SQL
DECLARE STOCK_070 CURSOR FOR
SELECT
A.CLIENT_ID,
C1.CUR_ASMT_SCD,
FROM VSTOCK A
LEFT JOIN VASSES C1
ON C1.CLIENT_ID = A.CLIENT_ID
WHERE
B1.STKPL_RULE_NBR = :STRSN-STKPL-RULE-NBR
AND DATE(A.CDTTM) >= :IOB3-DATE1
AND DATE(A.CDTTM) <= :IOB3-DATE2
*RESTART
AND
(A.CLIENT_ID = :STOCK-CLIENT-ID
OR
A.CLIENT_ID > :STOCK-CLIENT-ID)
*RESTART
ORDER BY
CASE WHEN C1.CUR_ASMT_SCD = '06'
THEN 1
WHEN C1.CUR_ASMT_SCD = '04'
THEN 2
WHEN C1.CUR_ASMT_SCD = '07'
THEN 3
,A.CLIENT_ID
END
END-EXEC.
EXEC SQL
This works without the CASE statements. But, of course, after the CASE is added the behaviour is messed up because the RESTART doesn't account for the CASEs.
To further explain - its a cursor, so its called, say, a MaxCall of 3 times (MaxCall defined in the program, not shown here). Then the cursor is closed. Then if the user requires more results, the cursor is RESTARTED. Hence why the restart code is important - it tells the Database to not start at the beginning all over again.
For example,
This dataset - (in the format A.CLIENT_ID-C1.CUR_ASMT_SCD) = (20-6,21-6,22-6,23-6,01-4,27-04,29-4).
Should display in this order:
20,21,22,23,01,27,29
If there is a MaxCall of 3, and there is NO RESTART CODE in the SQL - it would return
20,21,22,20,21,22,20,21,22 ... ad infinitum.
(which explains why a Restart is needed).
With the currently shown Restart (after the CASE statements in Order by were added):
20,21,22,23,27,29
Leaving some results out (because Client 01 is lower than 23 and is so discarded).
So, What I need is a way to alter the Restart Code to account for the added CASE Statements in the Order By Clause.
Is there a way to solve this via SQL?