---
title: "Parameterizing an SQL IN clause?"  
description: "Parameterizing an SQL IN clause?"  
author: "Anonymous User"  
published: 2013-04-17  
updated: 2013-04-17  
canonical: https://www.mindstick.com/forum/773/parameterizing-an-sql-in-clause  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 1 minute  

---

# Parameterizing an SQL IN clause?

Hi All!\
How do I parameterize a query containing an IN [clause](https://www.mindstick.com/forum/33937/difference-between-throw-exception-and-throw-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.\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)! \

## Replies

### Reply by AVADHESH PATEL

Hi Chintoo!\
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);}


---

Original Source: https://www.mindstick.com/forum/773/parameterizing-an-sql-in-clause

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
