Dynamic SQL results into temp table in SQL Stored procedure

后端 未结 8 1364
孤独总比滥情好
孤独总比滥情好 2020-11-28 10:08

The code is as follows:

ALTER PROCEDURE dbo.pdpd_DynamicCall 
@SQLString varchar(4096) = null

AS

Begin

    create TABLE #T1 ( column_1 varchar(10) , colu         


        
8条回答
  •  -上瘾入骨i
    2020-11-28 11:01

    Try:

    SELECT into #T1 execute ('execute ' + @SQLString )
    

    And this smells real bad like an sql injection vulnerability.


    correction (per @CarpeDiem's comment):

    INSERT into #T1 execute ('execute ' + @SQLString )
    

    also, omit the 'execute' if the sql string is something other than a procedure

提交回复
热议问题