dynamic sql query result evaluate

I have a service that invokes a dynamic sql adapter service. I want to be able to pass in any query and format the results in a structure, e.g.

input :
select a, b from table


column (document list)
rows (document list)
value (column(num))

I am able to populate the column document list, but not the rows because of the dynamic nature of the query. I can build the value of the expression I want to evaluate, i.e. %selectDynamicOutput/results/myRowValueForColA%; however, I cannot then evaluate it.

A bit complicated to describe, but I’m hoping someone has run across it before-- question can be reduced to how to recursively evaluate an expression.

I had to create a java service to do this. Doesn’t look like there’s anything that can be done with flow.