title: How to pass string parameter with `IN` operator in stored procedure SQL Server 2008
body: <p>I have a stored procedure when I execute it I got error         </p>
  
  <blockquote>
    <p>Conversion failed when converting the varchar value '+@dptId+' to data type int</p>
  </blockquote>
  
  <p>I am getting <code>DepartmentId</code> as a string like <code>(1,3,5,77)</code> and am passing this to my stored procedure.</p>
  
  <p><strong><a href="http://sqlfiddle.com/#!3/12923/8" rel="noreferrer">SQL FIDDLE</a></strong></p>
  
  <pre><code>create table dummy (id int,name varchar(100),DateJoining Datetime, departmentIt int)
  
  insert into dummy values (1,'John','2012-06-01 09:55:57.257',1);
  insert into dummy  values(2,'Amit','2013-06-01 09:55:57.257',2);
  insert into dummy  values(3,'Naval','2012-05-01 09:55:57.257',3);
  insert into dummy  values(4,'Pamela','2012-06-01 09:55:57.257',4);
  insert into dummy  values(5,'Andrea','2012-09-01 09:55:57.257',3);
  insert into dummy  values(6,'Vicky','2012-04-01 09:55:57.257',4);
  insert into dummy  values(7,'Billa','2012-02-01 09:55:57.257',4);
  insert into dummy  values(8,'Reza','2012-04-01 09:55:57.257',3);
  insert into dummy  values (9,'Jacob','2011-05-01 09:55:57.257',5);
  </code></pre>
  
  <p>Query I tried:</p>
  
  <pre><code>declare @startdate1 varchar(100) ='20120201'
  declare @enddate1 varchar(100)='20130601'
  declare @dptId varchar(100)='3,4'
  
  select * 
  from dummy
  where DateJoining &gt;= @startdate1 and DateJoining &lt; @enddate1 
    and departmentIt IN (@dptId);
  </code></pre>