Solved

Does rtrim remove whitespace other than spaces?

Posted on 2012-03-29
10
355 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
  • 5
  • 5
10 Comments
 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher 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:ScottPletcher
ScottPletcher 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
 
LVL 69

Expert Comment

by:ScottPletcher
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher 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:
ScottPletcher 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adventure works database .msi 4 62
MS SQL page split per second is high 19 77
TSQL mapping detailed records to group records 9 44
Help with SQL - TOP 10 by date and by group 13 34
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now