SSMS 结果到网格 - CRLF 未保留在复制/粘贴中 - 有更好的技术吗?
当我在网格中有一个结果集时,例如:
SELECT 'line 1
line 2
line 3'
或
SELECT 'line 1' + CHAR(13) + CHAR(10) + 'line 2' + CHAR(13) + CHAR(10) + 'line 3'
使用嵌入的 CRLF,网格中的显示似乎用空格替换它们(我猜这样它们将显示所有数据)。
问题是,如果我正在代码生成脚本,我不能简单地剪切和粘贴它。我必须转换代码以打开光标并打印相关列,以便我可以从文本结果中复制并粘贴它们。
是否有任何更简单的解决方法可以在结果网格的复制/粘贴操作中保留 CRLF?
网格有用的原因是我当前正在为不同列中的同一对象生成多个脚本 - 一列中的 bcp、另一列中的 xml 格式文件、另一列中的表创建脚本等...
When I have a result set in the grid like:
SELECT 'line 1
line 2
line 3'
or
SELECT 'line 1' + CHAR(13) + CHAR(10) + 'line 2' + CHAR(13) + CHAR(10) + 'line 3'
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.
Is there any simpler workaround to preserve the CRLF in a copy/paste operation from the results grid?
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
此问题已在 SSMS 16.5 build 13.0.16000.28 中得到修复,并添加了一个选项在复制/保存时保留 CR/LF(更多详细信息)(连接错误)。
这将导致
CR
、LF
和当您复制单元格时,CRLF
将被视为换行符。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).
This will cause
CR
,LF
, andCRLF
to be treated as newlines when you copy a cell.为自己回答这个问题,因为我永远不记得这是在哪里:
Answering this for myself because I can never remember where this is:
警告:此功能肯定还存在某种错误。
首先,我已经好几个月没有碰过这个选项了,最近又重新启动了。
我有一个包含多个列的查询,其中一列包含客户反馈(带有换行符)。当我将结果粘贴到 Google Docs / Excel 中时,反馈会变成一行(如我所愿)。
然后我将查询复制到另一个文件并再次运行它。这次结果包含换行符!
因此,要么存在非常奇怪的错误,要么存在某些秘密快捷方式更改当前窗口的设置。如果其他人看到这种行为,我很感兴趣。
Warning: There's definitely some kind of bug still with this feature.
First of all, I haven't touched the option in months and have recently rebooted.
I had a query with several columns, one of which contained customer feedback (with linefeeds). When I pasted the results into Google Docs / Excel the feedback went into one line (as I wanted).
I then copied the query to another file and ran it again. This time the results contained line breaks!
So either there is a very odd bug, or some secret shortcut that changes the setting for the current window. Interested if anyone else sees this behavior.
这是一个黑客,但尝试这个:
将结果集包装在 REPLACE (.....,CHAR(13)+CHAR(10),CHAR(182)) 中以保留换行符,然后您可以将它们替换回来
输出:
将它们替换回 SQL:
输出:
或在一个好的文本编辑器中。
it is a hack, but try this:
wrap your result set in a REPLACE (.....,CHAR(13)+CHAR(10),CHAR(182)) to preserve the line breaks, you can then replace them back
OUTPUT:
replace them back in SQL:
output:
or in a good text editor.
您可以做的一件事是将结果发送到文件,然后使用能够监视文件更改的编辑器,该编辑器具有理解输出的卓越功能。
One thing you can do is send results to a file, then use an editor capable of watching a file for changes which has superior capabilities for understanding the output.