将动态SQL结果存储到SQL存储过程中的临时表中 [英] Dynamic SQL results into temp table in SQL Stored procedure
本文介绍了将动态SQL结果存储到SQL存储过程中的临时表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码如下:
ALTER PROCEDURE dbo.pdpd_DynamicCall
@SQLString varchar(4096) = null
AS
Begin
create TABLE #T1 ( column_1 varchar(10) , column_2 varchar(100) )
insert into #T1
execute ('execute ' + @SQLString )
select * from #T1
End
问题是我想调用不同的过程来返回不同的列。
因此,我将必须一般性地定义表#T1。
但是我不知道如何。
The problem is that I want to call different procedures that can give back different columns. Therefore I would have to define the table #T1 generically. But I don't know how.
有人可以帮助我解决这个问题吗?
Can anyone help me on this problem?
推荐答案
尝试:
SELECT into #T1 execute ('execute ' + @SQLString )
闻起来像是SQL注入漏洞,真是不好。
And this smells real bad like an sql injection vulnerability.
更正(根据@CarpeDiem的评论):
correction (per @CarpeDiem's comment):
INSERT into #T1 execute ('execute ' + @SQLString )
'执行'
如果sql字符串不是过程字符串
also, omit the 'execute'
if the sql string is something other than a procedure
这篇关于将动态SQL结果存储到SQL存储过程中的临时表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文