title: How to preserve an ampersand (&) while using FOR XML PATH on SQL 2005
body: <p>Are there any tricks for preventing SQL Server from entitizing chars like &amp;, &lt;, and >?  I'm trying to output a URL in my XML file but SQL wants to replace any '&amp;' with '<code>&amp;amp;</code>'</p>
  
  <p>Take the following query:</p>
  
  <pre><code>SELECT 'http://foosite.com/' + RTRIM(li.imageStore)
          + '/ImageStore.dll?id=' + RTRIM(li.imageID)
          + '&amp;raw=1&amp;rev=' + RTRIM(li.imageVersion) AS imageUrl
  FROM ListingImages li
  FOR XML PATH ('image'), ROOT ('images'), TYPE
  </code></pre>
  
  <p>The output I get is like this (&amp;s are entitized):</p>
  
  <pre><code>&lt;images&gt;
    &lt;image&gt;
      &lt;imageUrl&gt;http://foosite.com/pics4/ImageStore.dll?id=7E92BA08829F6847&amp;amp;raw=1&amp;amp;rev=0&lt;/imageUrl&gt;
    &lt;/image&gt;
  &lt;/images&gt;
  </code></pre>
  
  <p>What I'd like is this (&amp;s are not entitized):</p>
  
  <pre><code>&lt;images&gt;
    &lt;image&gt;
      &lt;imageUrl&gt;http://foosite.com/pics4/ImageStore.dll?id=7E92BA08829F6847&amp;raw=1&amp;rev=0&lt;/imageUrl&gt;
    &lt;/image&gt;
  &lt;/images&gt;
  </code></pre>
  
  <p>How does one prevent SQL server from entitizing the '&amp;'s into '<code>&amp;amp;</code>'?</p>