SQL Server – Inconsistent Line Breaks in SSMS

sql serversql-server-2012ssms

Probably more of a SQL Management Studio question than SQL, per se, but when I run the following simple query:

SELECT results = 'Foo' + CHAR(13) + CHAR(10) + 'Bar'

I appear to get different results depending on whether I choose "Results to Grid" or "Results to Text".

With SSMS set to "Results to Text", I get (as expected):

results
--------
Foo
Bar

(1 row affected)

But with SSMS set to "Results to Grid", then copy and paste the results, I get

Foo  Bar

Best Answer

There is an option to change this behavior, go to Tools > Options > Query Results > SQL Server > Results to Grid, and check the box for "Retain CR/LF on copy or save":

enter image description here

You may have to exit and re-load SSMS for this change to take effect.