How to Remove All Newline from a Variable in SQL Server

How I can remove all NewLine from a variable in SQL Server?

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;

How do I remove line feed characters when selecting data from SQL Server?

The syntax of your statment looks wrong, maybe you can try with something like this:

Select Replace(Replace(@str,CHAR(10),''),CHAR(13),'')

The inner replace relaces LF and the outer replace replace CR

Replace a newline in TSQL

Actually a new line in a SQL command or script string can be any of CR, LF or CR+LF. To get them all, you need something like this:

SELECT REPLACE(REPLACE(@str, CHAR(13), ''), CHAR(10), '')

Remove/update line breaks from string in sql columns

If line breaks are always at the end of BOOKTITLE then you can do this update

UPDATE BOOKTABLE SET BOOKTITLE = LEFT(BOOKTITLE, LEN(BOOKTITLE) - 2)

Removing newline char from string on upload

As comments have pointed out, on windows, instead of: LINES TERMINATED BY '\n' it requires the additional \r like: LINES TERMINATED BY '\r\n'



Related Topics



Leave a reply



Submit