T-SQL: How to use parameters in dynamic SQL?

后端 未结 4 1762
春和景丽
春和景丽 2020-11-30 11:33

I have the following dynamic query which is working fine without the WHERE clause, which is expecting UNIQUEIDENTIFIER.

When I pass it in,

4条回答
  •  独厮守ぢ
    2020-11-30 11:42

    You must pass in the parameters to sp_executesql. See MSDN for details.

    ...
     WHERE 
        CreatedBy = @p
    ...
    
    EXECUTE sp_executesql @sql, N'@p UNIQUEIDENTIFIER', @p = @p_CreatedBY
    

提交回复
热议问题