We have a table with a column MyFunction
nvarchar()
that contains the name of a certain table valued function.
There are different functions so the number of columns can differ per function.
Is there a way to call the function as a string?
For example FunctionA
is a function, Set @MyFunction = 'FunctionA' then call MyFunction('x','y')
Is there a way to store the results in a tempTable since we don't know the number of columns up front?
Thanks in advance
Yes, you can do it using dynamic SQL:
EXEC sp_executesql N'select * from MyFunction(''x'', ''y'')'
Yes, you can, but you need global temp table:
EXEC sp_executesql N'select * into ##test from MyFunction(''x'', ''y'')'; select * from ##test;
Hope this works for you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.