SSMS ignores final \r\n / CRLF / Carriage Return + Line Feed in PRINT and RAISERROR
In SSMS, when using PRINT and/or RAISERROR to display messages in the "Messages" tab, if the final two characters on the line are the Carriage Return, Line Feed combination (i.e. "\r\n" or "CHAR(13) + CHAR(10)" or "CHAR(0x0D) + CHAR(0x0A)" ) then they are ignored (or "eaten") and no newline is issued as expected. BUT, if either Carriage Return OR Line Feed individually are used, then a newline is issued as expected. This is inconsistent and it should be that the Carriage Return + Line Feed combination is not ignored at the end of a line being printed.
Other forms of white-space (i.e. space and tab) are likewise not ignore. It is only Carriage Return + Line Feed, and only when used in combination.
This behavior seems to only happen in SSMS. I have also tested using SQLCMD and capturing messages in a C# application and both of those register the newline at the end of the line as expected.
I have tested with SSMS versions:
* v17.1 (14.0.17119.0)
* 2014 (12.0.5203.0)

Thanks for reporting this. We’ll review and prioritize appropriately.
7 comments
-
Bill Jetzer commented
Huh. It's not even possible to write code to compensate for the behavior.
Try something like this:
```
If end of line = CR+LF then
print everything to the left of the CR+LF
print empty string
else
print the string
```And you'll realize that printing a _blank_ string actually prints a _space_! I verified that this is SQL Server behavior, not SSMS behavior, by printing a blank string in Azure Data Studio and noting the space in the output. Repro script below.
```
print '----'; print ''; print rtrim(''); print left('',0); print null; print '----';
```There is a workaround for SSMS, but then you'll get extra blank lines in other tools:
```
If end of line = CR+LF then
print everything to the left of the CR+LF
print CR+LF -- SSMS will print one blank line, all others will print 2 as expected
else
print the string
``` -
Bill Jetzer commented
I can confirm that it seems to be peculiar to SSMS. Both Azure Data Studio and DBeaver print the expected output.
-
Solomon Rutzky commented
This is still an issue for SSMS v18.0 [RTM] (SQL Server Management Studio 15.0.18118.0).
-
Solomon Rutzky commented
This is still an issue for SSMS v18.0 RC1 (SQL Server Management Studio 15.0.18098.0).
-
Solomon Rutzky commented
This is still an issue for SSMS v18.0 Preview 7 (SQL Server Management Studio 15.0.18092.0).
-
Solomon Rutzky commented
This bug still exists in SSMS 18.0 Preview 6. Here is a simple test:
------------------------------------------------------------------
PRINT 'A';
PRINT 'B' + CHAR(0x0D) + CHAR(0x0A); -- NO NEWLINE in SSMS
PRINT 'C';
PRINT 'D' + CHAR(0x0D); -- newline is there
PRINT 'E';
PRINT 'F' + CHAR(0x0A); -- newline is there
PRINT 'G';
PRINT 'H' + CHAR(0x0D) + CHAR(0x0A) + CHAR(0x0D) + CHAR(0x0A); -- 1 newline is there, not 2
PRINT 'I';
------------------------------------------------------------------ -
Solomon Rutzky commented
I originally submitted this bug via: