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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Removing the embedded spaces in a string

Author  Topic 

tissa
Starting Member

3 Posts

Posted - 2005-02-03 : 23:59:03
How to remove the embedded spaces

string1 = 'abc def xyz'
to output 'abcdefxyz'

using a select sql

I know how to remove space ( one space) or n spaces but not variable number of embedded spaces ( abc|def|||||xyz where '|' is one space )

select replace( surname, ' ', '' ) from tbemployee

Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-02-04 : 00:23:17
Is this you want?

select replace( surname, '|', '' ) from tbemployee

Madhivanan
Go to Top of Page

tissa
Starting Member

3 Posts

Posted - 2005-02-04 : 07:26:33
Not really.....

write a select statement to remove the spaces in a string

eg for the string is 'abc def klm xyz'

expected result is 'abcdefklmxyz'

Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-02-04 : 07:38:25
madhivanan is right.... try the example below:


Declare @myStr varchar(100)
Set @myStr = 'abc def klm xyz'

Select @myStr, replace(@myStr,' ','')


Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Go to Top of Page

tissa
Starting Member

3 Posts

Posted - 2005-02-06 : 17:21:39
Thanks madhivanan

Yes it is correct

Corey, thanks for the sql
Go to Top of Page
   

- Advertisement -