title: How to export from SQL Server to XML
body: <p>What is the easiest way to export to XML from SQL Server [Table or view] to XML?</p>
  
  <p>This is what I have done till now</p>
  
  <p><strong>Execute Sql Task</strong></p>
  
  <pre><code>SELECT * FROM Production.Product 
  FOR XML AUTO, TYPE, ROOT('Data')
  </code></pre>
  
  <p><em>ResultSet</em> XML</p>
  
  <p>in left result set section I have created new variable 0 User::XMLVal</p>
  
  <p><strong>Script Task</strong></p>
  
  <pre><code> Dim sw As New IO.StreamWriter("D:\Apps\SSIS\test.xml")
      sw.Write(Dts.Variables("User::XMLVal").Value.ToString())
  
  
      sw.Dispose()
  </code></pre>