Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I insert data that contains a line feed character into the database. Then I retrieve that data. I am using this script to attempt to remove the line feed while selecting the data from SQL:

Select Replace(Replace stringname,char(10),'',char(32),'')) from tablename

The replace function seems to execute, but it does not remove the line feed correctly.

like image 522
charu Avatar asked Feb 20 '15 11:02

charu


People also ask

How do I delete a line feed character in SQL?

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).

How do I remove leading characters from SQL?

SQL Server TRIM() Function The TRIM() function removes the space character OR other specified characters from the start or end of a string. By default, the TRIM() function removes leading and trailing spaces from a string.

How remove CR LF in SQL?

Finally we use the ASCII CHAR(13) to identify and remove Carriage Return( \r ), and use the ASCII CHAR(10) to identify and remove Line Feed ( \n ). These ASCII Characters we need to use in side the REPLACE() Function to remove the CRLF Character from a String.

How do you change a line break in SQL Server?

In SQL Server, we can use the CHAR function with ASCII number code. We can use the following ASCII codes in SQL Server: Char(10) – New Line / Line Break. Char(13) – Carriage Return.


2 Answers

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

like image 76
Jose Marfil Avatar answered Oct 19 '22 08:10

Jose Marfil


Shouldn't it be Select Replace(Replace(stringname,char(10),''),char(13),'') from tablename?

Also you could use single replace Select Replace(stringname,char(13)+char(10),'') from tablename.

char(32) corresponds to a space symbol

like image 1
user2316116 Avatar answered Oct 19 '22 07:10

user2316116