views:

98

answers:

5
+11  A: 

You need to use an UPDATE statement!

The replace in the SELECT just changes the output not the data in the table.

BEGIN TRAN
UPDATE Customers SET Address = REPLACE(Address, char(10) + char(13), ' ') .... etc

--Check you like the change
SELECT * FROM Customers
--COMMIT --uncomment this to commit the changes.
pjp
When it is okay you uncomment the --COMMIT part and run it again. Apart from that, good answer, just a little clarification. Otherwise we will get a new question here at stackoverflow.
Gertjan
A: 

hi, the problem is the when first replace is completed in the text char(10) and char(13) are replaced with ' ' and the next replaces nerev do nothing

IordanTanev
Not true, parts where the CHAR(10) and CHAR(13) are used **together** are replaced by with a space, when a CHAR(10) is standing "alone" it will become a ;. Check the results in his result panel.
Gertjan
+1  A: 
UPDATE Customers
   SET Address = REPLACE(.....)
n8wrl
+1  A: 

When you perform a replace inside a select only the data "selected" is changed. So the replace is done just before showing you the data. The table data is not touched by a select. The data in the column needs to be updated via an update statement like:

UPDATE customers SET
    Address = REPLACE(Address,CHAR(10)+CHAR(13), ' ')
Gertjan
If only fields had methods like Replace
pjp
:) Good point. I will edit my comment.
Gertjan
+2  A: 

That would be:

UPDATE customers SET Address = REPLACE(REPLACE(REPLACE(Address,CHAR(10)+CHAR(13),' '),CHAR(10),';'),CHAR(13),';')
Stefan Haubold