SQL Syntax - Remove blank space Padding from string

I have data stored in a string column, and it has white space blank padding on either side:

table: person

'     john   '
' jane  '

I would like to remove the left and right space padding on either side - and the padding length is unknown.
Something like:?

Left(name, CHARINDEX (' ', name, CHARINDEX (' ', name) + 1) - 1)

Open in new window

Who is Participating?
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.

try this..

SELECT ltrim(rtrim(name))

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
TRIM(name) will do the job for you.
Sorry TRIM is not there in SQL Server. rushShah is correct. You can also use:
SELECT rtrim(ltrim(name))
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

This removes all whitespace, including tabs, carriage returns and line feeds. Further, it can be easily modified to trim any set of characters – just make @charstotrim a parameter.

CREATE FUNCTION dbo.trim(@input varchar(8000)) returns varchar(8000) as
declare @charstotrim varchar(100)
select @charstotrim =’ ‘+char(9)+char(10)+char(13)
while charindex(left(reverse(@input),1),@charstotrim) >0
select @input=left(@input,datalength(@input)-1)
while charindex(left(@input,1),@charstotrim) >0
select @input=substring(@input,2,datalength(@input)-1)
return @input
Rajkumar GsSoftware EngineerCommented:
To remove right & left spaces in all data, execute this query

UPDATE urTable SET urColumn = LTRIM(RTRIM(urColumn ))

Replace with your actual table name & column name to update

Now you can verify using this query

SELECT urColumn FROM urTable

robthomas09Author Commented:
thanks - will try and let you know
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
Query Syntax

From novice to tech pro — start learning today.