title: SQL Server discarding SPACE during GROUP BY
body: <p>Looks like SQL Server (tried on 2008 R2) is doing an <code>RTRIM</code> on columns in <code>GROUP BY</code> clause. Did anyone notice this? Am I missing something here?</p>
  
  <p>The two selects are returning the same result set in the query below, which should not be the case I believe.</p>
  
  <pre><code>declare @t table(Name varchar(100), Age int)
  insert into @t values ('A', 20)
  insert into @t values ('B', 30)
  insert into @t values ('C', 40)
  insert into @t values ('D', 25)
  insert into @t values (' A', 21)
  insert into @t values ('A ', 32)
  insert into @t values (' A ', 28)
  
  select
      Name,
      count(*) Count
  from @t
  group by Name
  
  select
      rtrim(Name) RtrimmedName,
      count(*) Count
  from @t
  group by rtrim(Name)
  </code></pre>
  
  <p>Please let me know your thoughts...</p>