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 2005 Forums
 Transact-SQL (2005)
 remove commas

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-03-08 : 12:23:39
how can i take a field and remove all commas from teh field

so select name,address from customer but if there is a comma in address it should remove it?

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-03-08 : 12:39:06
Use the replace function

SELECT [Name], replace([Address], ',', '') AS [Address]
FROM table1
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-03-08 : 12:40:44
[code]SELECT name , REPLACE(address, ',', '') AS address
FROM Customer[/code]

-Ryan

EDIT: Dang, too slow. :)
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-03-08 : 12:41:57
great -- didn't know there was a replace funtion
can i make a strip function to remove commas and # and anything else i see as an issue and then just use that function? would this work? how?
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-03-08 : 12:57:46
Just call it multiple times

SELECT [Name], replace(replace([Address], ',', ''), '#', '') AS [Address]
FROM table1

Go to Top of Page
   

- Advertisement -