title: Saving the XML results to variable or table in SQL
body: <p>How can I save a XML to variable or table which is generated by SQL stored procedure?</p>
  
  <p>Here's my sample:</p>
  
  <pre><code>DECLARE @ReportResultXml TABLE(RXml XML)    
  DECLARE @ResultXml  XML = NULL
  
  INSERT @ReportResultXml EXEC (@Script + ' FOR XML RAW, ROOT, XMLSCHEMA, ELEMENTS')
  SELECT @ResultXml = RXml FROM @ReportResultXml
  EXEC Repor.ProcInsert 1, @ResultXml
  
  SELECT @ResultXml
  </code></pre>
  
  <p>The <code>@Script</code> variable contains this SQL query:</p>
  
  <pre><code>DECLARE @PeriodID INT
  SET @PeriodID = 12
  SELECT TOP 10 PeriodID, Name
  FROM Agent.Points
  WHERE PeriodID = @PeriodID
  </code></pre>
  
  <p>That statement will generate the following error: </p>
  
  <blockquote>
    <p>The FOR XML clause is not allowed in a INSERT statement.</p>
  </blockquote>