I will preface this question by saying, I do not think it is solvable. I also have a workaround, I can create a stored procedure with an OUTPUT to accomplish this, it is jus
Here is the solution
Solution 1: Return the dynamic string from Function then
Declare @SQLStr varchar(max) DECLARE @tmptable table () set @SQLStr=dbo.function() insert into @tmptable Exec (@SQLStr) select * from @tmptable
Solution 2: call nested functions by passing parameters.