title: Where IN a Comma delimited string
body: <p>I would like to retrieve certain users from a full list of a temp table #temptable.
  The query looks like this:</p>
  
  <pre><code>DECLARE @List varchar(max)
  SELECT @List = coalesce(@List + ',','') + '''' + StaffCode + ''''
  FROM tblStaffs
  
  SELECT UserName
  FROM #temptable
  WHERE #temptable.StaffCode IN (@List)
  </code></pre>
  
  <p>I can tell @List is in a right format:</p>
  
  <pre><code>'AAA','ABB','BBB','CCC','DDD','MMM'
  </code></pre>
  
  <p>And if I change it to </p>
  
  <pre><code>WHERE #temptable.StaffCode IN ('AAA','ABB','BBB','CCC','DDD','MMM')
  </code></pre>
  
  <p>It certainly works, then why not IN (@List)?</p>