If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
You can't. "SELECT INTO" is not a dynamic statement.
Quote:
SELECT INTO statement
The SELECT INTO statement produces a result table consisting of at most one row, and assigns the values in that row to host variables. If the table is empty, the statement assigns +100 to SQLCODE and '02000' to SQLSTATE and does not assign values to the host variables. If more than one row satisfies the search condition, statement processing is terminated, and an error occurs (SQLSTATE 21000).
Invocation
This statement can be embedded only in an application program. It is an executable statement that cannot be dynamically prepared.
Not as such. However you can use
DECLARE GLOBAL TEMPORARY TABLE mycount (myrowcount integer)
SET str = 'INSERT INTO SESSION.mycount SELECT COUNT(*) FROM ... WHERE ...'
EXECUTE IMMEDIATE str
SELECT myrowcount INTO var FROM SESSION.mycount
DECLARE RC CURSOR WITH RETURN FOR
SELECT * FROM SESSION.TEMP;
DECLARE GLOBAL TEMPORARY TABLE SESSION.TEMP(TOT INTEGER) ON COMMIT PRESERVE ROWS;
INSERT INTO SESSION.TEMP SELECT COUNT(*) FROM IRNI.A_RT_SENTINEL_LOG;
OPEN RC;
Error message:
Exception occurred while running:
"A database manager error occurred.[IBM][CLI Driver][DB2] SQL0873N Objects encoded with different encoding schemes cannot be referenced in the same SQL statement. SQLSTATE=53090"
As a wild guess, was IRNI.A_RT_SENTINEL_LOG created with CCSID UNICODE while the database was created using some other codeset? Or the other way around. Not a good thing to do - read all the restrictions.
You might have to do something like:
declare myint integer;
DECLARE RC CURSOR WITH RETURN FOR
SELECT * FROM SESSION.TEMP;
DECLARE GLOBAL TEMPORARY TABLE SESSION.TEMP(TOT INTEGER) ON COMMIT PRESERVE ROWS;
SELECT COUNT(*) into myint FROM IRNI.A_RT_SENTINEL_LOG;