Executing dynamic SQL in a SQLServer 2005 function

后端 未结 5 742
死守一世寂寞
死守一世寂寞 2020-11-28 14:10

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

5条回答
  •  星月不相逢
    2020-11-28 14:48

    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.

提交回复
热议问题