title: XML declaration with "FOR XML PATH" in SQL Server 2005
body: <p>Below is a simplified version of a query that I have already created.  The query works fine, but I cannot figure out how to get the XML declaration at the top of the generated XML.  I've tried multiple things and searched far and wide on the Google, but alas I cannot seem to find out how to do this ... or even if it is possible.</p>
  
  <pre><code>select 
      'Dimension' "@type",
      (
          select
              (
                  select
                      'X102' "TransactionType",
                      convert(varchar, getdate(), 104) "Transfer/TransferDate",
                      convert(varchar, getdate(), 108) "Transfer/TransferTime"
                  for xml path (''), type
              ) "TransactionInformation"
          for xml path (''), type
      )
  for xml path ('DimensionImport'), type
  </code></pre>
  
  <p><strong>Gives me...</strong></p>
  
  <pre><code>&lt;DimensionImport type="Dimension"&gt;
      &lt;TransactionInformation&gt;
          &lt;TransactionType&gt;X102&lt;/TransactionType&gt;
          &lt;Transfer&gt;
              &lt;TransferDate&gt;21.01.2010&lt;/TransferDate&gt;
              &lt;TransferTime&gt;15:46:36&lt;/TransferTime&gt;
          &lt;/Transfer&gt;
      &lt;/TransactionInformation&gt;
  &lt;/DimensionImport&gt;
  </code></pre>
  
  <p><strong>I'm wanting...</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;DimensionImport type="Dimension"&gt;
      &lt;TransactionInformation&gt;
          &lt;TransactionType&gt;X102&lt;/TransactionType&gt;
          &lt;Transfer&gt;
              &lt;TransferDate&gt;21.01.2010&lt;/TransferDate&gt;
              &lt;TransferTime&gt;15:46:36&lt;/TransferTime&gt;
          &lt;/Transfer&gt;
      &lt;/TransactionInformation&gt;
  &lt;/DimensionImport&gt;
  </code></pre>
  
  <p>Thank you in advance for any help you might be able to lend.</p>