1

I have a binary file (uploaded .txt file with some code on every row CRLF) in my SQL server.

When I execute the following code:

SELECT CAST(TheBinary as varchar(Max)) FROM MyTable

I get a string of the file in the results as expected. However, when I copy this result and paste this string back in a new notepad, the line breaks and new lines do not follow and everything is kept in a single line.

I know the newline and carrige returns are there in the string because I tried REPLACE function on char(10) and char(13) and it replaces those. I also tried to "print" the results back into an empty file and the newlines are there.

The issue is simply when I copy and paste the contents of the select in the results in SSMS.

What can I do to make it copy the new lines correctly?

Agneum
  • 727
  • 7
  • 23
  • 1
    Does this answer your question? [How to correctly insert newline in nvarchar](https://stackoverflow.com/questions/53115490/how-to-correctly-insert-newline-in-nvarchar/53115559#53115559) – Thom A Jul 21 '21 at 09:17
  • Yes perfect, that was the option I was looking for. I assumed it was on by default and got confused if it was an encoding issue. https://stackoverflow.com/questions/8387976/line-breaks-lost-in-sql-server – Agneum Jul 21 '21 at 09:18

1 Answers1

0

IN SSMS

Tools -> Options...

> Query Results 
  > SQL Server 
    > Results to Grid 

set "Retain CR\LF on copy or save" to true.
Agneum
  • 727
  • 7
  • 23