title: Output XML directly to file from SQL server
body: <p>Output the results (XML) of a stored procedure to a file.</p>
  
  <p>I have a stored procedure in SQL server that creates an XML file. It currently displays the resulting XML and I have to manually save as a file.</p>
  
  <p>I have tried to call the procedure from Powershell, <a href="https://stackoverflow.com/questions/56275948/outputting-large-xml-file-from-sql-with-powershell">as in this question</a>, this works for small files but not for large (>1gb files) as Powershell tries to store the entire thing as a variable and it quickly runs out of memory.</p>
  
  <p>I'm opening this as a new question as I think there should be a way of doing this within SQL server (or a better way of doing it with Powershell).</p>