---
title: "Parameterizing an SQL IN clause?"  
description: "Parameterizing an SQL IN clause?"  
author: "Anonymous User"  
published: 2013-05-06  
updated: 2013-05-06  
canonical: https://www.mindstick.com/forum/818/parameterizing-an-sql-in-clause  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 1 minute  

---

# Parameterizing an SQL IN clause?

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
How do I parametric a query containing an IN clause with a [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) number of [arguments](https://answers.mindstick.com/qa/92535/what-are-the-different-types-of-arguments), like this one?\
[select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) * from Tags where Name in ('ruby','rails','scruffy','rubyonrails')order by Count descIn this query, the number of arguments could be anywhere from 1 to 5.\
I would prefer not to use a [dedicated](https://www.mindstick.com/articles/13048/questions-that-render-a-helping-hand-for-hiring-dedicated-wordpress-developer) [stored procedure](https://www.mindstick.com/articles/803/using-stored-procedure-in-asp-dot-net) for this (or XML), but if there is some fancy [SQL Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server) 2008 specific way of doing it elegantly, I am open to that.\
Please help me!\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!\

## Replies

### Reply by AVADHESH PATEL

Hi Ankita!\
Here's a quick-and-dirty technique I have used:\
select * from Tagswhere '|ruby|rails|scruffy|rubyonrails|'like '%|' + Name + '|%'So here's the C# code:\
string[] tags = new string[] { "ruby", "rails", "scruffy", "rubyonrails" };const string cmdText = "select * from tags where '|' + @tags + '|' like '%|' + Name + '|%'";\
using (SqlCommand cmd = new SqlCommand(cmdText)) { cmd.Parameters.AddWithValue("@tags", string.Join("|", tags);}Two caveats:\
The performance is terrible. like "%...%" queries are not indexed.Make sure you don't have any |, blank, or null tags or this won't workThere are other ways to accomplish this that some people may consider cleaner, so please keep reading.\


---

Original Source: https://www.mindstick.com/forum/818/parameterizing-an-sql-in-clause

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
