Retain Carriage Return And Line Feeds On Copy Or Save In SQL Server 2016

Introduction

The default behavior for retaining the line break (carriage return) has changed and it may not be what you will need in your actual development environment. In SSMS 2016, if you copy any result from the Result Grid and paste it in a Notepad or any text editor, you will notice that the carriage returns and line feeds are not in place. However, this can also be configured, as per your convenience. 
 
To change this behavior, follow the steps given below.

Tools - Options - Query Results - SQL Server - Results to Grid - "Retain CR/LF on copy or save", you may refer the image given below to get it done.

Example

Execute the query given below by unchecking the checkbox (which is the default behavior).
  1. SELECT- 'This is a demo text
  2. For test purpose only' AS demotext
The output while copying to Notepad is shown below.

demotext
-------------------
This is a demo text for test purposes only
Now, execute the same query after checking the mentioned checkbox and get the result as –
demotext
------------------
This is a demo text
for test purpose only

Conclusion

With this small tip, we learned how to configure SSMS to retain carriage return and line feeds, while copying the text from Result Grid, which is not default in the new SSMS introduced with SQL Server 2016.

Thanks for reading. Please share your feedback. 

Next Recommended Reading Create Or Alter In SQL Server 2016