使用REPLACE添加回车符返回字符串不起作用

时间:2019-02-03 22:58:31

标签: sql tsql

哪里有'〜'我想在回车符中输入。

我希望数据看起来像这样。

   Computer software for processing patient identification.
   On-demand printable wristband.
   Providing a web-based system and on-line Portal.

我尝试使用下面的代码,但是它唯一要做的就是删除'〜'。

 SELECT REPLACE(' Computer software for processing patient identification.~  
 On-demand printable wristband.~  Providing a web-based system and on-line 
 Portal.~','~', CHAR(13)+CHAR(10));

是否知道如何添加回车符?

先谢谢您

5 个答案:

答案 0 :(得分:2)

当我运行SQL查询并通过选项“ show END Line”将查询输出复制到notpad ++中时,出现在屏幕下方。您的查询是正确的。enter image description here

答案 1 :(得分:1)

现有答案正确(您的查询正确,其他解决方案也正确)。我认为问题是SQL Server Management Studio在网格模式下无法正确显示新行。

如果只需要显示一列,请尝试使用“结果转换为文本”选项(在“查询” /“结果转换为”菜单中)。如果需要显示多个列,并且其中至少一个包含换行符,则应使用另一种工具来查看数据。一种解决方案是使用Red Gate SQL Prompt提供的“在Excel中打开”选项。

答案 2 :(得分:0)

我会简单地做:

SELECT REPLACE(' Computer software for processing patient identification.~  
 On-demand printable wristband.~  Providing a web-based system and on-line 
 Portal.~',
               '~', '
');

答案 3 :(得分:0)

如果使用的是Management Studio,则更改设置:工具->选项->查询结果->结果到网格->在复制或保存时保留CR / LF。重新启动Management Studio。

enter image description here

答案 4 :(得分:0)

很抱歉,您没有回复。一旦在HotDocs中使用了包含此代码的视图,它们就会显示在不同的行中。当我将返回的行放入Notepad ++并查看所有符号均打开时,没有看到任何CR或LR字符,这使我感到困惑。这就是为什么我认为它不起作用。

感谢您的回复!

SR