title: T-SQL: How can I compare two variables of type XML when length > VarChar(MAX)?
body: <p>Using only SQL Server 2008 R2 (this is going to be in a stored proc), how can I determine if two variables of type XML are equivalent?</p>
  
  <p>Here is what I want to do:</p>
  
  <pre><code>DECLARE @XmlA   XML
  DECLARE @XmlB   XML
  
  SET @XmlA = '[Really long Xml value]'
  SET @XmlB = '[Really long Xml value]'
  
  IF @XmlA = @XmlB
      SELECT 'Matching Xml!'
  </code></pre>
  
  <p>But as you probably know, it returns:</p>
  
  <blockquote>
    <p>Msg 305, Level 16, State 1, Line 7 The XML data type cannot be
    compared or sorted, except when using the IS NULL operator.</p>
  </blockquote>
  
  <p>I can convert to <code>VarChar(MAX)</code> and compare, but that only compares the first 2MB. Is there another way?</p>