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