title: SQL Server: Text column to files with filenames from table
body: <p>I have this table:</p>
  
  <pre><code>CREATE TABLE Files 
  (
      [Id] [bigint] NOT NULL
      [FileName] [VarChar](500) NOT NULL,
      [FileXML] [nvarchar](max) NOT NULL
  )
  </code></pre>
  
  <p>What I want is to create an XML file for every record in this table.</p>
  
  <p>Filename has to be the value of FileName + '.xml', content has to be the value of FileXML.</p>
  
  <p>I tried to use xp_cmdshell, but it doesn't accept varchar(max) as parameter, and the length of my XML is greater than 8000 in some cases.</p>
  
  <p>I tried looking for this but I didn't really find anything.</p>
  
  <p>The solution doesn't have to be fancy, it just has to work, this is a one-time action.</p>