HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Carriage return/line feed stopped working in SQL Server

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
linereturnstoppedcarriagesqlworkingfeedserver

Problem

SQL was working fine last week with the old CHAR(13)+CHAR(10) for line feed/carriage return.

DECLARE @text varchar(2000)
SET @text = 
'Attached is your new reporting ID and temporary password.'
+ CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10)
+ 'The new login/password will be updated  on ' + Convert(char(10), @ticketdate,101)


Last week this ran as expected giving me nicely formatted text with a space between the lines.

This week, the same code on the same server is returning one long run-on line of text.

This seems like this is a collation issue? Or something like that?

The code has worked as expect so something changed, but I can't identify what might have changed.

This seems like it could be collation issue? But it appears to be the default latin setting.

Solution

Since you're outputting to Grid View, I suspect that the option to Retain CR/LF on copy or save is disabled. Enable this option, open a new query window, run the same query, and your newline characters should now come across after you paste results out of a Grid View. In SSMS 2017, the Setting can be found under Tools → Options → Query Results → SQL Server → Results to Grid. The path is in a similar location in other versions of SSMS.

Alternatively, if you want to apply this setting to the immediate query window only, enable the Retain CR/LF on copy or save option which can be found under Query → Query Options... → Results → Grid. These settings won't be saved across all query windows, rather they are only applied to the current one.

Context

StackExchange Database Administrators Q#187680, answer score: 11

Revisions (0)

No revisions yet.