Sql-server – Carriage return/line feed stopped working in SQL Server

sql serverssms

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.

Best Answer

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 ToolsOptionsQuery ResultsSQL ServerResults to Grid. The path is in a similar location in other versions of SSMS.

enter image description here

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 QueryQuery Options...ResultsGrid. These settings won't be saved across all query windows, rather they are only applied to the current one.