title: Overcome 2GB limit on XML output in SQL Server
body: <p>There is a daily process that produces an XML file from an SQL Server database.</p>
  
  <p>Internally it is implemented as a series of nested "FOR XML..." queries enclosed in a stored procedure. A Powershell script executes the stored procedure and processes the output.</p>
  
  <p>Recently, the amount of data generated by the stored procedure exceeded 2 GB and the process died because of a hard limit on XML data type size in SQL Server.</p>
  
  <p>My question is, what would be the best approach to bypass that limit? Obviously, using the XML data type in SQL Server is a no-go but I guess people somehow <em>do</em> generate large XML files off SQL Server databases.</p>