Home >Database >Mysql Tutorial >Why Are My Dynamic SQL Parameters in T-SQL Not Returning Results?
Dynamic SQL Parameters in T-SQL
You have a dynamic query that works well without a WHERE clause that takes a UNIQUEIDENTIFIER as input. However, when you try to pass in the parameter, no results are returned.
The key issue here is the parameter passing in the sp_executesql function. The following code demonstrates the correct way to pass in parameters:
... WHERE CreatedBy = @p ... EXECUTE sp_executesql @sql, N'@p UNIQUEIDENTIFIER', @p = @p_CreatedBY
By passing in the parameter separately, you can ensure that the correct value is used when executing the dynamic SQL.
The above is the detailed content of Why Are My Dynamic SQL Parameters in T-SQL Not Returning Results?. For more information, please follow other related articles on the PHP Chinese website!