SSMS 结果到网格 - CRLF 未保留在复制/粘贴中 - 有更好的技术吗?

2022-01-12 00:00:00 formatting sql-server ssms

当我在网格中有一个结果集时:

When I have a result set in the grid like:

SELECT 'line 1
line 2
line 3'

SELECT 'line 1' + CHAR(13) + CHAR(10) + 'line 2' + CHAR(13) + CHAR(10) + 'line 3'

使用嵌入的 CRLF,网格中的显示似乎用空格替换它们(我猜这样它们会显示所有数据).

With embedded CRLF, the display in the grid appears to replace them with spaces (I guess so that they will display all the data).

问题是,如果我正在代码生成脚本,我不能简单地剪切和粘贴它.我必须转换代码以打开光标并打印相关列,以便我可以从文本结果中复制和粘贴它们.

The problem is that if I am code-generating a script, I cannot simply cut and paste this. I have to convert the code to open a cursor and print the relevant columns so that I can copy and paste them from the text results.

是否有任何更简单的解决方法可以在结果网格的复制/粘贴操作中保留 CRLF?

Is there any simpler workaround to preserve the CRLF in a copy/paste operation from the results grid?

网格有用的原因是我目前正在为不同列中的同一对象生成许多脚本 - 一列中的 bcp 输出,另一列中的 xml 格式文件,另一列中的表创建脚本等...

The reason that the grid is helpful is that I am currently generating a number of scripts for the same object in different columns - a bcp out in one column, an xml format file in another, a table create script in another, etc...

推荐答案

此问题已在 中修复SSMS 16.5 build 13.0.16000.28 添加了在复制/保存时保留 CR/LF 的选项 (更多详细信息)(连接错误).

This issue has been fixed in SSMS 16.5 build 13.0.16000.28 with the addition of an option to preserve CR/LF on copy/save (more details) (Connect bug).

  1. 工具 > 选项
  2. 展开查询结果 > SQL Server > 结果到网格
  3. 勾选Retain CR/LF on copy or save
  4. 重启 SSMS

这将导致 CRLFCRLF 在您复制单元格时被视为换行符.

This will cause CR, LF, and CRLF to be treated as newlines when you copy a cell.

相关文章