Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSMS Results to Grid - CRLF not preserved in copy/paste - any better techniques?

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...

like image 998
Cade Roux Avatar asked Apr 20 '10 23:04

Cade Roux


People also ask

How do you save results in SSMS?

In SQL Server Management Studio, after you have run a query, go to the Results tab. 2. Right-click the result set and click Save Results As: 3.

How do you wrap code in SSMS?

Click Options on the Tools menu. Click Text Editor. Open the appropriate language folder (or All Languages to affect all languages). Select Word wrap.

How do I save SSMS results in Excel?

Launch SSMS and connect to the required database. 2. In Object Explorer, go to the database that you want to export to Excel. Invoke the shortcut menu and go to Tasks > Export Data.

How do I get rid of the red lines in SSMS?

Try pressing ctrl + Shift + r to refresh intellisense and remove the red squiggly underline.


1 Answers

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.

like image 134
Charles Gagnon Avatar answered Oct 01 '22 12:10

Charles Gagnon