Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Space Deletion

Author  Topic 

sanjay5219
Posting Yak Master

240 Posts

Posted - 2010-03-26 : 11:21:12
Dear All,


I have one table in which i have 100000 with four column
o1,o2,o3,o4

Suddenly i got to know that some vcalues are haveing sapce like
A1
A1
A1
Request all of you to tell me how to remove these space from SQL Server

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-26 : 11:24:21
What are the data types?
And where in your given example are the spaces?

normally if you have trailing spaces in a varchar colum you can do this:
update table
set column = rtrim(column)

RTRIM() deletes trailing spaces.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-26 : 11:24:54
use REPLACE(yourfield,' ','') to remove space

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 2010-03-26 : 11:36:28
I have tried ltrim, rtrim but still facing same thing

Data types are c=varchar
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-26 : 11:51:38
We still cannot see where are the spaces in your given example.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 2010-03-26 : 11:52:40
Data is coming like this
'A1'
' A2'
' A3'
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-27 : 02:28:37
quote:
Originally posted by sanjay5219

Data is coming like this
'A1'
' A2'
' A3'



May be its having hard space. try this too

update table
set column =ltrim(rtrim(replace(column , char(160), char(32))))


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -