Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Trim a field

Status
Not open for further replies.

mGis

Programmer
Mar 22, 2001
29
US
I have a field in a table the has leading spaces.

How can I change the fields to remove any leading spaces?

I was thinking of something like below, but I dont think its correct.

---

update tableOne
set name = (select ltrim(name) from tableOne)

---

Any thoughts on how I should do this?

Thanks.

 
Code:
update tableOne
set name = ltrim(name)

ltrim is not a standard function, rather use

Code:
update tableOne
set name = trim(leading from name)

if it is supported by your DBMS.
 
I tried (using sql200, so ltrim is valid):

update tableOne
set name = (select ltrim(name) from tableOne)


I recevied the following error:
Subquery returned more than one value.
This is not permitted when the subquery follows =,!=,<,<=,>,>=
or when the subquery is used as an expression.

I think the problems is coming from when I am trying to update the same table/field that the select statement is calling.

what about:
update tableOne n1
set n1.name =
(
select ltrim(n2.name) from tableOne n2
where n1.name=n2.name
)

Any thoughts? I will use any suggestions. Simply speaking, I want to update fields in the table to get rid of leading spaces.

Thanks,
Michael
 
Did you try my first suggestion?

Code:
update tableOne
set name = ltrim(name)
 
This is the syntax:

UPDATE tblOne SET [Name] = LTRIM([Name])

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top