Change in SQL 2012 SSMS grid output behavior

Leave a comment

October 28, 2013 by Kenneth Fisher

It’s one of those things that always aggravated me but not really enough to complain about. When you run a query to grid in SSMS then copy and paste the value to a query window it stripped the carriage return/line feed.

-- Setup code
CREATE TABLE GridTest (String varchar(50))
GO

INSERT INTO GridTest VALUES ('Line
Broken
In
String'), 
('Line'+char(13)+'Broken'+char(13)+'With'+char(13)+'char(13)'),
('Line'+char(10)+'Broken'+char(10)+'With'+char(10)+'char(10)')
GO

Note that I’m testing with a string broken up by hitting enter, a string where I manually add char(13) and a string where I manually add char(10).

Run a SELECT * to a grid output.

Change in SQL 2012 SSMS grid output behavior

In SSMS 2008 R2 (and prior) when I copy the values and paste them into a query window (or notepad etc) and I get this:

Line  Broken  In  String
Line Broken With char(13)
Line Broken With char(10)

Not a big deal you might say, but when you are looking at sys.sql_modules or sys.dm_exec_query_text and copy and paste out code for a stored procedure, a view or even a relatively simple query it can be very aggravating.

Well when I copy and paste out of SSMS for SQL 2012 I get this.

Line
Broken
In
String
Line
Broken
With
char(13)
Line
Broken
With
char(10)

Woo hoo! All three of them display the carriage returns and line feeds. It may be a minor change but you have no idea how much I appreciate it. I should probably note that when I tried it by adding a CHAR(13) and a CHAR(10) I got the following (which is also rather aggravating but over all I think I’m still happier).

Line

Broken

With

char(13)

and

char(10)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 3,753 other subscribers

Follow me on Twitter

ToadWorld Pro of the Month November 2013
%d bloggers like this: