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).
使用嵌入式CRLF,网格中的显示将用空格替换它们(我想这样它们将显示所有的数据)。
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?
是否有更简单的方法在结果网格的复制/粘贴操作中保存CRLF ?
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...
网格之所以有用,是因为我目前正在为不同列中的同一对象生成大量脚本——一列中有一个bcp,另一列中有一个xml格式文件,另一列中有一个表创建脚本,等等……
4 个解决方案
#1
19
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).
这个问题在SSMS 16.5 build 13.0.16000.28中得到了修正,增加了一个选项来在copy/save上保存CR/LF(更多细节)(连接bug)。
- Tools > Options
- 工具>选项
- Expand Query Results > SQL Server > Results to Grid
- 将查询结果> SQL Server >扩展到网格
- Tick Retain CR/LF on copy or save
- 在拷贝或保存时保留CR/LF
- Restart SSMS
- 重启地对地导弹
This will cause CR
, LF
, and CRLF
to be treated as newlines when you copy a cell.
这将导致当您复制一个单元时,CR、LF和CRLF被视为新行。
#2
2
I believe this article has several techniques which can be useful: http://sqlblogcasts.com/blogs/martinbell/archive/2009/10/25/How-to-display-long-text-in-SSMS.aspx
我相信这篇文章有几个有用的技术:http://sqlblogcasts.com/blogs/martinbell/archive/2009/10/25/ how -to-display-long-text- ssms.aspx
#3
0
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.
您可以做的一件事是将结果发送到一个文件,然后使用一个编辑器,该编辑器能够监视一个文件的更改,这些更改具有更好的理解输出的能力。
#4
-1
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
将结果集封装在一个替换(……,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)
)
OUTPUT:
输出:
----------------------
line 1¶line 2¶line 3
(1 row(s) affected)
replace them back in SQL:
用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.
或者用一个好的文本编辑器。
#1
19
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).
这个问题在SSMS 16.5 build 13.0.16000.28中得到了修正,增加了一个选项来在copy/save上保存CR/LF(更多细节)(连接bug)。
- Tools > Options
- 工具>选项
- Expand Query Results > SQL Server > Results to Grid
- 将查询结果> SQL Server >扩展到网格
- Tick Retain CR/LF on copy or save
- 在拷贝或保存时保留CR/LF
- Restart SSMS
- 重启地对地导弹
This will cause CR
, LF
, and CRLF
to be treated as newlines when you copy a cell.
这将导致当您复制一个单元时,CR、LF和CRLF被视为新行。
#2
2
I believe this article has several techniques which can be useful: http://sqlblogcasts.com/blogs/martinbell/archive/2009/10/25/How-to-display-long-text-in-SSMS.aspx
我相信这篇文章有几个有用的技术:http://sqlblogcasts.com/blogs/martinbell/archive/2009/10/25/ how -to-display-long-text- ssms.aspx
#3
0
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.
您可以做的一件事是将结果发送到一个文件,然后使用一个编辑器,该编辑器能够监视一个文件的更改,这些更改具有更好的理解输出的能力。
#4
-1
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
将结果集封装在一个替换(……,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)
)
OUTPUT:
输出:
----------------------
line 1¶line 2¶line 3
(1 row(s) affected)
replace them back in SQL:
用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.
或者用一个好的文本编辑器。