Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8659079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:55:10+00:00 2026-06-12T15:55:10+00:00

Looks like SQL Server (tried on 2008 R2) is doing an RTRIM on columns

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:55:11+00:00Added an answer on June 12, 2026 at 3:55 pm

    It’s actually doing the opposite, but the observable effects are the same.

    When comparing two strings of unequal length, one of the rules of SQL (the standard, not just SQL Server) is that the shorter string is padded with spaces until it’s the same length, and then the comparison is performed.

    If you want to avoid being surprised, you’ll need to add a non-space character at the end of each string.


    In fact, checking the standard text, it appears that there are two options:

    4.6 Type conversions and mixing of data types

    …

    When values of unequal length
    are compared, if the collating sequence for the comparison has
    the NO PAD attribute and the shorter value is equal to a prefix of
    the longer value, then the shorter value is considered less than
    the longer value. If the collating sequence for the comparison has
    the PAD SPACE attribute, for the purposes of the comparison, the
    shorter value is effectively extended to the length of the longer
    by concatenation of <space>s on the right.

    But all of the SQL Server collations I’m aware of are PAD SPACE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a large (1TB) table in SQL Server 2008 that looks something like this:
I'm using SQL Server 2008 and I have a view that looks like this:
I have a SQL Server Stored Procedure that looks like this: CREATE PROCEDURE [dbo].[my_stored_procedure]
I have a table in SQL Server which looks like this: ID Code Name
On SQL Server 2005, I have a complex multi-level allocation process which looks like
My SQL query looks like this... sekect * FROM mail_headers a LEFT JOIN mail_headers_body
I have a sql query which looks like this - NSString *createSQL = @SELECT
So I have a table in sql it looks like this controlnum taxyear payrollg
Hi there I have an SQL table that looks like this: CREATE TABLE IF
I have a line in my SQL Stored Procedure that looks like this (works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.