将参数传递给sql server中的动态存储过程

问题描述:

hii all
我有一个带有一个字符串参数的Adynaic存储过程,并且我在exec中有一个探针

hii all
i have adynaic stored procedure which takes one string parameter and i have a probel in the exec

set @With ='' With TableX as (''+ @sqlQuery + '') select * from TableX where Country = '' + @CountryName
print @With 



有人能告诉我它的正确语法吗?



can anyone tell me the correct syntax of it, please???

不确定我是否有完整的答案,但有一些发现:

1.您没有添加结尾的撇号,因此sql无效.
2. print只会将查询写入输出而不执行.
3.在SQL批处理中,必须首先执行公用表表达式(即以...开头的东西).
Not sure I have a complete answer, but some observations:

1. You''re not adding a trailing apostrophe so the sql is invalid.
2. print will only write the query to output and not execute it.
3. Common table expressions (ie. things that start With) have to be the first thing to execute in a SQL batch.