参数化SQL IN子句 - Parameterize an SQL IN clause

问题:

How do I parameterize a query containing an IN clause with a variable number of arguments, like this one? 我该如何参数化包含一个带有可变数量参数的IN子句的查询,就像这样? ruby

SELECT * FROM Tags 
WHERE Name IN ('ruby','rails','scruffy','rubyonrails')
ORDER BY Count DESC

In this query, the number of arguments could be anywhere from 1 to 5. 在此查询中,参数的数量能够为1到5之间的任意值。 this

I would prefer not to use a dedicated stored procedure for this (or XML), but if there is some elegant way specific to SQL Server 2008 , I am open to that. 我不但愿为此(或XML)使用专用的存储过程,可是若是有一些特定于SQL Server 2008的优雅方法,我能够接受。 spa


解决方案:

参考一: https://stackoom.com/question/1Pqq/参数化SQL-IN子句
参考二: https://oldbug.net/q/1Pqq/Parameterize-an-SQL-IN-clause
相关文章
相关标签/搜索