问题
I wrote a function, StoogeFunk, that uses FOREACH against systables and syscolumns, to concatenate in a string the list of fields in a table (the name of which is passed as a function parameter). I surround with CAST/VARCHAR(30) the date fields, for reasons I dare not explain. So, I come to a point where I have in a string, SelectString, the equivalent of:
SELECT Name, CAST(DOB AS VARCHAR(30)) AS DOB, ShoeSize FROM Stooges
My function simply returns that LVARCHAR string (and it is a long one, due to many fields). That result-text SELECT works fine in a query window.
1.) Now, instead of returning that string (a simple "RETURN SelectString;" line before "END FUNCTION;"), I want to execute the string, returning from the function a nice, big, juicy bunch of records. I imagine something like an EVAL:
RETURN EVAL(SelectString);
How may I reach that dream?
2.) If the above is impossible, could I call the SelectString-result function externally?
EXECUTE EVAL(StoogeFunk("StoogeTable"))
How would that be workable?
来源:https://stackoverflow.com/questions/34938257/how-to-eval-a-select-string-and-execute