How to EVAL a SELECT String and EXECUTE

China☆狼群 提交于 2019-12-11 11:57:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!