Looks like SQL Server (tried on 2008 R2) is doing an RTRIM
on columns in GROUP BY
clause. Did anyone notice this? Am I missing something here?
The two selects are returning the same result set in the query below, which should not be the case I believe.
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)
Please let me know your thoughts...