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

charu picture charu · Feb 20, 2015 · Viewed 46.6k times · Source

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.

Answer

Jose Marfil picture Jose Marfil · Feb 20, 2015

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