Reputation: 399
I have a table of addresses that have certain addresses listed as 123 Clock St \nAPTB.
How do I remove the "\n" and have there be a space between the street address and apt number.
I tried using the Replace function, but it didn't seem to work. Am I formatting it correctly?
Here is what I was using:
Select * from address_table;
UPDATE address_table SET address = replace (address, '\n', '');
Upvotes: 0
Views: 3865
Reputation: 28196
The issue is probably the correct masking of you newline character. I have not yet found a solution for that but the following worked for me in Sql-server and MySql:
select replace(address,'
',' ');
In SQL it is permissible to have actual linefeeds in a string literal.
(I tried the otherwise suggested doubling of escape characters first, but for me it did not work it. Edit: The escape character solution does work too: http://rextester.com/IZCF14460 , but without doubling them.)
Upvotes: 0
Reputation: 394
As backslash ('\') is an escape character, you should double it :
Select * from address_table;
UPDATE address_table SET address = replace (address, '\\n', ' ');
Upvotes: 2