title: How to fix "The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator."
body: <p>This is what I have so far:</p>
  
  <pre><code>SELECT 
      account, ' ', message_type, 
      MAX(message_no) as max_message_no, message_text
  FROM
      (SELECT 
           account, message_type, message_no, message_text
       FROM  
           messages m 
       INNER JOIN 
           receivables r ON m.account = r.aracct
       WHERE 
           m.account IN (SELECT r.aracct AS account 
                         FROM receivables r 
                         WHERE r.balance &lt;&gt; 0)
           AND m.message_type = 'N') t1
  GROUP BY 
      t1.account, t1.message_type, t1.message_text
  </code></pre>
  
  <p>I keep getting the error message: </p>
  
  <blockquote>
    <p>The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.</p>
  </blockquote>
  
  <p>I essentially want the max <code>message_no</code> from each account and I want it to show the <code>message_text</code>, but it won't allow it because it is a <code>text</code> data type.</p>