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

巧了我就是萌 提交于 2020-01-02 17:29:09

问题


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.


回答1:


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




回答2:


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




回答3:


(select Replace( (select REPLACE(   ColName,CHAR(10),'')),char(13),''))
   as ColAlias

from YourTable


来源:https://stackoverflow.com/questions/28628342/how-do-i-remove-line-feed-characters-when-selecting-data-from-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!