Parameterizing a SQL IN clause?

Posted by Jeff Atwood on Stack Overflow See other posts from Stack Overflow or by Jeff Atwood
Published on 2008-12-03T16:16:43Z Indexed on 2010/06/09 20:32 UTC
Read the original article Hit count: 155

Filed under:
|
|

How do I parameterize a query containing an IN clause with a variable number of arguments, like this one?

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.

I would prefer not to use a dedicated stored procedure for this (or XML), but if there is some fancy SQL Server 2008 specific way of doing it elegantly, I am open to that.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server