问题:
How do I parameterize a query containing an IN
clause with a variable number of arguments, like this one? 我该如何参数化包含一个带有可变数量参数的IN
子句的查询,就像这样?
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之间的任意值。
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的优雅方法,我可以接受。
解决方案:
参考一: https://stackoom.com/question/1Pqq/参数化SQL-IN子句参考二: https://oldbug.net/q/1Pqq/Parameterize-an-SQL-IN-clause
来源:oschina
链接:https://my.oschina.net/u/4438370/blog/4314582