title: Assign result of dynamic sql to variable
body: <p>I'm doing dynamic SQL to convert all columns in a table a string</p>
  
  <p>so After after all I do</p>
  
  <pre><code>EXEC(@template); 
  </code></pre>
  
  <p>where @template is the dynamic generated query so: </p>
  
  <pre><code>col1  col2 col3
  ---------------
  1    7    13 
  2    8    14
  3    9    15
  4   10    16
  5   11    17
  6   12    18
  </code></pre>
  
  <p>(this results: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18)</p>
  
  <p>How do I assign to a variable the resulting string</p>
  
  <p>something like?</p>
  
  <pre><code>DECLARE  @result AS varchar(max);
   SET @result = EXEC(@template); 
  </code></pre>