This is a bit of a "note to self", but I've run into this error a couple of times now and the solution is not obvious from the error message. Searching the forums on the error also didn't provide an immediate answer. Until now
If you use a CTE (Common Table Expression), such as:
ENGINE SQLMSS SET DEFAULT_CONNECTION &CONNECTION
SQL SQLMSS PREPARE SQLOUT FOR
WITH cte1 AS (
SELECT 1 AS WHICH, A, B, C FROM TABLE1 WHERE C IS NOT NULL
UNION
SELECT 2 AS WHICH, A, B, 'dummy' AS C FROM TABLE1 WHERE C IS NULL
)
SELECT WHICH, A, B, C FROM cte1
ORDER BY C
;
END
TABLE FILE SQLOUT
PRINT *
END
You may get an error:
(FOC1400) SQLCODE IS -1 (HEX: FFFFFFFF)
: Microsoft SQL Native Client: [] Multiple-step OLE DB operation generated
: errors. Check each OLE DB status value, if available. No work was done.
L (FOC1406) SQL OPEN CURSOR ERROR. : SQLOUT
This is NOT (necessarily) because there's any error in your query. I was scratching my head after executing this query just fine from another (Java-based) SQL client, until I found an old post (by myself, even!) that contained the solution - but that was about a different topic.
The solution: You need to add below line to your ENGINE initialisation code to make WebFOCUS perform the query entirely in the SQL client (or something):
ENGINE SQLMSS SET CURSORS CLIENT
So it becomes:
ENGINE SQLMSS SET CURSORS CLIENT
ENGINE SQLMSS SET DEFAULT_CONNECTION &CONNECTION
SQL SQLMSS PREPARE SQLOUT FOR
WITH cte1 AS (...)
WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :