title: Conversion failed when converting the varchar value 'xxx' to data type int
body: <p>I have declared a variable &amp; appended strings with comma separated. This variable i want to use for a where condition for another query. </p>
  
  <pre><code>declare @AllIDs varchar(max)
  set @AllIDs = ''
  
  select 
      @AllIDs = (@AllIDs + cast(ID as varchar(10)) + ',') 
  from EmployeeDetail WHERE Code In(
  'ABC1','ABC2'
  )
  
  select @AllIDs
  
  select * from TBL_OT where EmployeeId In(@AllIDs)
  </code></pre>
  
  <p>The EmployeeId is of type int. so it is giving me error :-</p>
  
  <blockquote>
    <p>Conversion failed when converting the varchar value 'xxx' to data type
    int.</p>
  </blockquote>