title: Fetch multiple values and store in a single variable as comma separated values
body: <p>I am trying to fetch a number of values from a table and store it in a single variable as comma separated values so that I can use that variable as parameter in a different select statement.</p>
  
  <p>Here's the SQL Query:</p>
  
  <pre><code>DECLARE @AccCode VARCHAR(MAX)
  SELECT @AccCode = AccCode FROM Account WHERE (*some condition*) --returns more than 1 value
  SELECT * FROM AccountSet WHERE AccCode IN (@AccCode)  
  </code></pre>
  
  <p>The problem is that all the values returned from the first select query is not being stored in the @AccCode variable. Instead only the first returned value is being stored.  </p>
  
  <p>I am not sure if I'm missing something. Any help would be appreciated.  </p>
  
  <p>Thanks in advance..!!</p>