How can I can remove all NewLine from a variable in SQL Server?
I use SQL Server 2008 R2.
I need remove all NewLine in a variable in a T-Sql Command.
For example:
Declare @A NVarChar(500)
Set @A = ' 12345
25487
154814 '
Print @A
And it printed like this:
12345
25487
154814
But I want to get strings like this:
12345 25487 154814
I write this query, but it does not work:
Set @A = Replace(@A,CHAR(13),' ')
Remove and Replace Carriage Returns and Line Breaks in SQL Using SQL to remove a line feed or carriage return means using the CHAR function. A line feed is CHAR(10); a carriage return is CHAR(13).
Char(13) is the carriage return and char(10) is the line feed symbol. How to remove line feed from a SQL Server column ? To remove the carriage return or line feed directly from a SQL column, simply apply a replace method to remove it and replace with a space or an empty string.
-- Using both \r\n SELECT 'First line. \r\nSecond Line. ' AS 'New Line'; -- Using both \n SELECT 'First line.
You must use this query
Declare @A NVarChar(500);
Set @A = N' 12345
25487
154814 ';
Set @A = Replace(@A,CHAR(13)+CHAR(10),' ');
Print @A;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With