将参数传递给SQL Server中的IN子句
可能的重复项:
参数化SQL IN子句?
SQL Server-具有已声明变量的In子句
Possible Duplicates:
Parameterizing a SQL IN clause?
SQL Server - In clause with a declared variable
我在将参数传递给'IN'子句时遇到问题.我正在使用以下查询.
I am facing problem passing parameters to 'IN' clause. I am using the below query.
查询:
SELECT Topics.Topic_Id FROM Topics
Where Topic_Description IN (''+ @Topics +'')
当参数具有单个值时,此查询有效.我的参数可以用逗号分隔多个值,例如:一个",两个",三个",四个".但是,只要有多个参数,查询就会失败.如何克服这个问题?请提出建议.
This query works when the parameter has single value. My parameter can have comma separated multiple values like : 'one','two','three','four'. But the query fails whenever there are multiple parameters. How to get over this ? Please suggest.
谢谢
我必须将以上内容用作存储过程的一部分.我必须将选择查询的结果放入光标,如下所示:
I have to use the above as part of a stored procedure. I have to take the result of the select query into a cursor like below:
DECLARE cur_TopicIDs CURSOR FOR SELECT Topics.Topic_Id从主题何处 Topic_Description IN(''+ @Topics +'').... etc
DECLARE cur_TopicIDs CURSOR FOR SELECT Topics.Topic_Id FROM Topics Where Topic_Description IN (''+ @Topics +'')....etc
在这种情况下,如何按照其他链接的建议使用动态sp
In this case how can I use dynamic sp as suggested in other links
从此处使用任何拆分功能: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648
Use any of the split functions from here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648