Solved

Does rtrim remove whitespace other than spaces?

Posted on 2012-03-29
10
359 Views
Last Modified: 2012-03-29
This select yields the results below.  rtrim doesn't seem to trim the last character.  I'm wondering if rtrim removes spaces but not tabs or something.

select len(loginwindows) as loginlen, len(rtrim(loginwindows)) as loginlenrtrim, left(loginwindows, 8) as login8, loginwindows from general.employees where lastname = 'langley'

loginlen      loginlentrim    login8           loginwindows
9                9                      LL004838      LL004838 
0
Comment
Question by:Barry Sweezey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 500 total points
ID: 37784219
RTRIM/LTRIM remove only spaces.
0
 

Author Comment

by:Barry Sweezey
ID: 37784222
How do I remove all whitespace?
0
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 500 total points
ID: 37784233
Easiest way to remove others is to use REPLACE ... but if you only want to replace trailing values it's quite a bit trickier.

To remove *all* tabs, carriage returns and line feeds, you can do this:

UPDATE
SET column = REPLACE(REPLACE(REPLACE(column, CHAR(9), ''), CHAR(13), ''), CHAR(10), '')
WHERE
    column LIKE '%' + CHAR(9) + '%' OR
    column LIKE '%' + CHAR(13) + '%' OR
    column LIKE '%' + CHAR(10) + '%'
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 37784251
If you want to be really thorough, you could also check for CHAR(11) and CHAR(15), although the ones above are the most common in Windows.
0
 

Author Comment

by:Barry Sweezey
ID: 37784392
Thanks for the quick response.

I ran the query below and received the message (0 row(s) affected).  The original query yields the sames results.  How can I identify the last character in the string?


UPDATE general.employees
SET LoginWindows = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LoginWindows, CHAR(9), ''), CHAR(10), ''), CHAR(11), ''), CHAR(13), ''), CHAR(15), '')
WHERE
    LoginWindows LIKE '%' + char(9) + '%' OR
    LoginWindows LIKE '%' + char(10) + '%' OR
    LoginWindows LIKE '%' + char(10) + '%' OR
    LoginWindows LIKE '%' + char(13) + '%' OR
    LoginWindows LIKE '%' + char(15) + '%'
0
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 500 total points
ID: 37784409
SELECT
    DISTINCT
    ASCII(RIGHT(LoginWindows, 1))
FROM general.employees
WHERE
    ASCII(RIGHT(LoginWindows, 1)) < 32 OR
    ASCII(RIGHT(LoginWindows, 1)) > 127
0
 

Author Comment

by:Barry Sweezey
ID: 37784418
I corrected a line; no difference.

    LoginWindows LIKE '%' + char(10) + '%' OR
    LoginWindows LIKE '%' + char(11) + '%' OR
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 37784581
Re-post of query:

Try this query to identify the trailing char(s) :

SELECT
    DISTINCT
    ASCII(RIGHT(LoginWindows, 1))
FROM general.employees
WHERE
    ASCII(RIGHT(LoginWindows, 1)) < 32 OR
    ASCII(RIGHT(LoginWindows, 1)) > 127
0
 

Author Comment

by:Barry Sweezey
ID: 37784979
Results:

(No column name)
160

So it's a Non-breaking space.

I updated the update query (below) and it worked.

UPDATE general.employees
SET LoginWindows = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LoginWindows, CHAR(9), ''), CHAR(10), ''), CHAR(11), ''), CHAR(13), ''), CHAR(15), ''), CHAR(160), '')
WHERE
    LoginWindows LIKE '%' + char(9) + '%' OR
    LoginWindows LIKE '%' + char(10) + '%' OR
    LoginWindows LIKE '%' + char(11) + '%' OR
    LoginWindows LIKE '%' + char(13) + '%' OR
    LoginWindows LIKE '%' + char(15) + '%' OR
    LoginWindows LIKE '%' + char(160) + '%'
0
 

Author Closing Comment

by:Barry Sweezey
ID: 37784994
I appreciate ScottPletcher's hanging with me until the problem was solved.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Set the max value for a column 7 41
TSQL mapping detailed records to group records 9 66
Insert from Stored Procedure where some field/s > 0 7 47
SQL- GROUP BY 4 25
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question