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

发布于 2024-08-29 19:07:04 字数 450 浏览 3 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

鹿! 2024-09-05 19:07:04

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

  1. 工具>>选项
  2. 展开查询结果> SQL服务器>结果到网格
  3. 勾选复制或保存时保留 CR/LF
  4. 重新启动 SSMS

这将导致 CRLF当您复制单元格时,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).

  1. Tools > Options
  2. Expand Query Results > SQL Server > Results to Grid
  3. Tick Retain CR/LF on copy or save
  4. Restart SSMS

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

我为君王 2024-09-05 19:07:04

为自己回答这个问题,因为我永远不记得这是在哪里:

在此处输入图像描述

Answering this for myself because I can never remember where this is:

enter image description here

七秒鱼° 2024-09-05 19:07:04

警告:此功能肯定还存在某种错误。

首先,我已经好几个月没有碰过这个选项了,最近又重新启动了。

我有一个包含多个列的查询,其中一列包含客户反馈(带有换行符)。当我将结果粘贴到 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.

孤芳又自赏 2024-09-05 19:07:04

这是一个黑客,但尝试这个:

将结果集包装在 REPLACE (.....,CHAR(13)+CHAR(10),CHAR(182)) 中以保留换行符,然后您可以将它们替换回来

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

输出:

----------------------
line 1¶line 2¶line 3

(1 row(s) affected)

将它们替换回 SQL:

select replace('line 1¶line 2¶line 3',CHAR(182),CHAR(13)+CHAR(10))

输出:

-------------------
line 1
line 2
line 3

(1 row(s) affected)

或在一个好的文本编辑器中。

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

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

OUTPUT:

----------------------
line 1¶line 2¶line 3

(1 row(s) affected)

replace them back in SQL:

select replace('line 1¶line 2¶line 3',CHAR(182),CHAR(13)+CHAR(10))

output:

-------------------
line 1
line 2
line 3

(1 row(s) affected)

or in a good text editor.

中性美 2024-09-05 19:07:04

您可以做的一件事是将结果发送到文件,然后使用能够监视文件更改的编辑器,该编辑器具有理解输出的卓越功能。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文