Loop issue in Procedure
virtualdatabase Sep 11, 2015 11:16 AMI'm having an issue I can't figure out if I'm doing something incorrect or there's a bug..
BEGIN
DECLARE string VARIABLES.ExecSTring;
DECLARE string VARIABLES.WhereClause;
DECLARE string VARIABLES.Tempcounter;
IF(MCDS_UTIL.proc_X_ByClientLayout.IN_Col2 IS NULL)
BEGIN
VARIABLES.WhereClause = '';
END
ELSE
BEGIN
VARIABLES.WhereClause = (((' WHERE Col2 = ' || chr(39)) || MCDS_UTIL.proc_X_ByClientLayout.IN_Col2) || chr(39));
END
CREATE LOCAL TEMPORARY TABLE temp_2 (name string);
CREATE LOCAL TEMPORARY TABLE TEMP_TJ (Col1 string, Col2 string, Col3 string, Col4 string, Col5 string, Col6 string, Col7string, Col8 string, Col9 string, Col10 string, Col11 date, Col12 date, Col13 string, Col14 string);
LOOP ON (SELECT SYS.Tables.Name FROM SYS.Tables WHERE (SYS.Tables.Name LIKE (('%_' || MCDS_UTIL.proc_X_ByClientLayout.IN_ClientNum) || '_%')) AND (SYS.Tables.SchemaName = 'MCDS_src') AND (SYS.Tables.SchemaName <> 'MCDS') AND (lower(SYS.Tables.Name) LIKE (('%_' || MCDS_UTIL.proc_X_ByClientLayout.IN_LayoutNum) || '.X%'))) AS txncursor
BEGIN
VARIABLES.ExecSTring = (('select Col1, Col2,Col3,Col4,Col5,Col6, Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14 FROM ' || txncursor.Name) || VARIABLES.WhereClause);
EXEC sysadmin.logMsg(level => 'INFO', context => 'org.teiid', msg => VARIABLES.ExecSTring); <----I CAN SEE THE LOOP works HERE
EXECUTE IMMEDIATE VARIABLES.ExecSTring AS Col1 string, Col2 string, Col3 string, Col4 string, Col5 string, Col6 string, Col7string, Col8 string, Col9 string, Col10 string, Col11 date, Col12 date, Col13 string, Col14 string INTO TEMP_TJ;
VARIABLES.Tempcounter = (SELECT COUNT(*) FROM TEMP_TJ);
EXEC sysadmin.logMsg(level => 'INFO', context => 'org.teiid', msg => ('INSIDE LOOP: ' || VARIABLES.Tempcounter)); <--- I SEE THIS BUT THE COUNTER is only showing the current Loop iteration... it SHOULD INCREMENT.. shouldn't it ? IS a "commit" needed ?
END
EXEC sysadmin.logMsg(level => 'INFO', context => 'org.teiid', msg => ('Before RETURN Select: ' || VARIABLES.Tempcounter));<---I SEE THIS BUT THE COUNTER is only showing the current Loop iteration...
SELECT * FROM TEMP_TJ;<--- NO DATA is ever returned when I call the procedure
BEGIN
EXEC sysadmin.logMsg(level => 'INFO', context => 'org.teiid', msg => ('AFTER RETURN Select: ' || VARIABLES.Tempcounter)); <--- I NEVER SEE THIS
END
END
Any thoughts/input/guidance Most appreciated!!
-Tom