title: Question, allocation of values in subquery
body: <p>Someone told me a sentence that I don't need to write Loop(while).
  for example,
  I wrote this sentence.</p>
  <pre><code>WHILE(@intFrom &lt;= @intTo)
      BEGIN
          SET @strSelectMonthCol = @strSelectMonthCol + ',ISNULL(SUM([M_'+CONVERT(VARCHAR, @intFrom)+']),0) AS M_'+CONVERT(VARCHAR, @intFrom)
          SET @strSelectSumCol = @strSelectSumCol + 'SUM(ISNULL([M_'+CONVERT(VARCHAR, @intFrom)+'],0)) +'
          SET @strPivot = @strPivot + '[M_' + CONVERT(VARCHAR, @intFrom) + '],'
          SET @intFrom += 1
      END
  </code></pre>
  <p>And then he gave me this sentence.</p>
  <pre><code>DECLARE @QUERY NVARCHAR(MAX)
  SET @QUERY = ''
  SELECT @QUERY = @QUERY + '[' + A.X_CD + '], '
  FROM ( SELECT DISTINCT TOP 10  X_CD FROM X_ITEM ) AS A
  SELECT @QUERY
  </code></pre>
  <p>How does @Query accumulate repeatedly without WHILE?</p>