title: Is there any way to group by a text column?
body: <p>I have this code:</p>
  
  <pre><code>select CAST(OPERATOR_NAME AS NVARCHAR(MAX)) as 'Utilizador',
  TERMINAL_DESCRIPTION as 'Terminal',
  DOCUMENT_DATE as 'Data de Inicio',
  PAYMENT_LIMIT_DATE as 'Data de Fim',
  ORIGIN_WAREHOUSE_NAME as 'Loja',
  DOCUMENT_TYPE_DESCRIPTION as 'Tipos de Documentos' 
  from MRD_DOCUMENT_HEADER 
  GROUP BY CAST(OPERATOR_NAME AS NVARCHAR(MAX))
  </code></pre>
  
  <p>But it gives me this error:</p>
  
  <blockquote>
    <p>Column <code>MRD_DOCUMENT_HEADER.TERMINAL_DESCRIPTION</code> is invalid in the select list because it is not contained in either an aggregate function or the <code>GROUP BY</code> clause.</p>
  </blockquote>
  
  <p>I tried <code>VARCHAR(100)</code> and <code>MAX</code> but that didn't work either.</p>
  
  <p>How can I get this working?</p>
  
  <hr>
  
  <p><em>Updated</em></p>
  
  <pre><code>SELECT DISTINCT
        Utilizador = OPERATOR_NAME 
      , Terminal = TERMINAL_DESCRIPTION 
      , [Data de Inicio] = DOCUMENT_DATE
      , [Data de Fim] = PAYMENT_LIMIT_DATE
      , Loja = ORIGIN_WAREHOUSE_NAME 
      , [Tipos de Documentos] = DOCUMENT_TYPE_DESCRIPTION
  FROM dbo.MRD_DOCUMENT_HEADER
  WHERE
         MRD_DOCUMENT_HEADER.DOCUMENT_TYPE_DESCRIPTION = (@DOCUMENT_TYPE_DESCRIPTION)
      OR MRD_DOCUMENT_HEADER.DOCUMENT_DATE = (@DOCUMENT_DATE)
      OR MRD_DOCUMENT_HEADER.PAYMENT_LIMIT_DATE =(@PAYMENT_LIMIT_DATE)
      OR MRD_DOCUMENT_HEADER.CORPORATION_ID = (@CORPORATION_ID)
  </code></pre>