FOR x IN (SELECT DISTINCT coname
FROM
table1
,table2
... etc
WHERE
table1.field1=table2.field3
.... etc.
??? AND ||p_SQL|| ???
)

LOOP

l_query= l_query ||
',' || 'max(DECODE (coname,'''||x.coname||''',cds.midpx,null"'||x.coname|| '"';

END LOOP;

l_query:=rtrim(l_query, ',')|| l_query_dist||p_SQL|| ' GROUP BY cds.storedate';


OPEN ChartOutput FOR l_query;

END;
END;
/

Don't know if it makes much sense withoiut the whole code. But still.
The whole thing works OK if in FOR...IN I don't use any parameters (say select fom a table)


Thanks in advance,

Shurik12.