SQL Server/SSMS: Confusions around clear understanding of CR, LF, Tab: Settings does not work

Ashwin Kanumoori 40 Reputation points
2023-10-07T15:44:07.55+00:00

I am observing that when SSMS settings are set to:

Scenario 1: Results to Grid

Case 1: Retain CR/LF values on copy or save is checked

Then, result shown in result tab, has a single line of text.

When I copy the text, and paste it in text file, then all escape characters - \r,\n are shown applied,

So the pasted content occupies more than one line based on CHAR(10), and CHAR(13) I have applied/inserted in the string

Case 2: Retain CR/LF values on copy or save is Un-checked

Then the same steps performed does not paste the results in multiple lines but in single line. Also, any escape sequence - char(10) or char(13) are replaced with single space.

Scenario 2: Results to Text (Just verifying the output text in result tab this context)

Scenario 3: Results to File (Just opening the file and verifying the text)

But in above 2 scenarios- 2 and 3, for both the cases -

case 1 : Retain CR/LF values on copy or save is checked

case 2 : Retain CR/LF values on copy or save is Un-checked

it gives the same results as case 1

So Does this work only for Results to Grid and

NOT

Results to Text and Results to File?

Or any other settings exist ?

Note:

Just to mention I am changing the settings and opening a new query window and executing.

(Also observed restarting SSMS)

SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 121.9K Reputation points MVP Volunteer Moderator
    2023-10-07T17:21:04.5166667+00:00

    This picture should be a hint:

    User's image

    The setting is on the page for Results to grid. So it is quite logical that it only applies to grid results and not to text results or results to file.

    As for the setting not applying to Results to text, it has always been the way that line breaks has resulted in line breaks in the output. The reason that Results to grid has this setting is that originally, CR/LF were always lost, because they were removed to fit the grid. But if you had a cell with something like SQL code, it wasn't fun to copy/paste. So they changed this with SQL 2012 to always retain line breaks. But then people who like to copy to Excel got mad. So eventually, they introduced this option to please everyone.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.