Why ltrim rtrim wont remove white space in select ltrim(rtrim('ABCDG '))?

SQL Server 2008
LVL 2
neehar gollapudiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vaibhav GoelMSBI , SQL ConsultantCommented:
Hello Neehar

I tired the same select ltrim(rtrim('ABCDG '))

it is working for me.

Do you have this data in this table. You can for other things like if there is a tab character or enter.

Vaibhav
0
PortletPaulEE Topic AdvisorCommented:
try this:

select ascii(right(columnX,1))
from (
    selct columnX from tableY where columnX like 'ABCDG%'
    ) d

Open in new window

It probably isn't a whitespace character that RTRIM deals with

once you know what the char number is, use REPLACE(columnX, CHAR(???), '')
0
Mark WillsTopic AdvisorCommented:
You might have 'special' characters hidden in there.

declare @vchar varchar(6) = ' ABCD '
declare @schar varchar(6) = 'ABCD' + char(10)

select @vchar,len(rtrim(ltrim(@vchar)))
select @schar,len(rtrim(ltrim(@schar)))

select patindex('%[^'+char(32)+'-'+char(126)+']%',@schar collate SQL_Latin1_General_CP850_Bin)  

Open in new window


Can explain the above in more detail....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Mark WillsTopic AdvisorCommented:
@paul - snap - same thoughts :)
0
PortletPaulEE Topic AdvisorCommented:
@mark - ditto - cheers!  (in between watching Ashes test)
0
Mark WillsTopic AdvisorCommented:
@paul, but it is lunch break now :)  (great minds think alike ? )
0
awking00Information Technology SpecialistCommented:
Just an observation - another good example of sql server needing to develop full regex functionality. POSIX [:space:] covers all white space i.e. space, line feed, carriage return, form feed, horizontal tab, and vertical tab) and could easily be us in a single replace statement. As it is, the following series of replaces should do the trick -
select replace(replace(replace(replace(replace(replace(string,char(9),''),char(10),''),char(11),''),char(12),''),char(13),''),char(32),'')
1
neehar gollapudiAuthor Commented:
thank you it was the carriage return.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.