title: Converting XML node values to comma separated values in SQL
body: <p>I am trying to convert XML node values to comma separated values but, getting a </p>
  
  <blockquote>
    <p>Incorrect syntax near the keyword 'SELECT'.
     error message</p>
  </blockquote>
  
  <pre><code>declare @dataCodes XML = '&lt;Root&gt;
                      &lt;List Value="120" /&gt;
                      &lt;List Value="110" /&gt;
                  &lt;/Root&gt;';
  
  DECLARE   @ConcatString VARCHAR(MAX)
  SELECT   @ConcatString = COALESCE(@ConcatString + ', ', '') + Code FROM (SELECT T.Item.value('@Value[1]','VARCHAR(MAX)') as Code  FROM  @dataCodes.nodes('/Root/List') AS T(Item))
  SELECT   @ConcatString AS Result
  GO
  </code></pre>
  
  <p>I tried to follow an <a href="http://www.databasejournal.com/features/mssql/converting-comma-separated-value-to-rows-and-vice-versa-in-sql-server.html" rel="nofollow">article</a> but not sure how to proceed further. Any suggestion is appreciated.</p>
  
  <p><strong>Expectation:</strong></p>
  
  <p>Comma separated values ('120,110') stored in a variable.</p>