DYNAMIC RESULT SETS 1
LANGUAGE SQL
 BEGIN


	            BEGIN
					    DECLARE crs CURSOR WITH RETURN FOR
						 SELECT DISTINCT
					            Variables_1.VarID,
					            StatementReference_1.bRead AS VariableReferenceType,
					            StatementReference_2.ResourceType,
					            StatementReference_2.ResourceID,
					            StatementReference_2.bRead AS ResourceReferenceType,
					            st.Description AS StatementType,
					            os.StartRow,
					            pth.PathStr,
					            pa.AliasName AS ProgramName,
					            pt.ProgramType,
					            prg.ProgramID,
					            os.OccurID
					     FROM StatementReference AS StatementReference_1
					               INNER JOIN Variables AS Variables_1 ON StatementReference_1.ResourceID = Variables_1.VarID
					               INNER JOIN StatementReference AS StatementReference_2 ON StatementReference_1.OccurID = StatementReference_2.OccurID
					                                                                            AND StatementReference_1.bRead <> StatementReference_2.bRead
					               INNER JOIN Statements st ON StatementReference_1.StatementType = st.StatementType
					               INNER JOIN OccurrencesStmt os ON StatementReference_1.OccurID = os.OccurID
					               INNER JOIN Paths pth ON os.PathID = pth.PathID
					               INNER JOIN Programs prg ON os.ProgID = prg.ProgramID
					               INNER JOIN ProgramAliases pa ON pa.ProgramID = prg.ProgramID AND pa.AliasType = 0
								   INNER JOIN ProgramTypes pt ON prg.ProgramTypeID = pt.ProgramTypeID
					     WHERE StatementReference_1.ResourceType = 4
					           AND StatementReference_2.ResourceType IN (1, 6, 9, 18, 19, 20, 21, 56, 61, 62, 69, 70, 77, 78, 81, 182, 189, 190, 193)
					           AND Variables_1.VarID IN (SELECT * FROM SESSION.numeric_param_temp)
					           AND StatementReference_1.bRead = 1
					           AND StatementReference_2.bRead = 2
					     ORDER BY Variables_1.VarID;
						
				        OPEN crs;
				
                END;
END	
