SQL Server : Remove a Newline (enter) in TSQL

This is how to replace (or remove) a newline character in a TSQL string. A newline produced with keyboard enter button or script CR, LF, and CR+LF.

Here below is an example: 


We need to use REPLACE function to remove the newline with the empty string. In SQL newline are CHAR(13) and CHAR(10), so we could make query as below:

SELECT REPLACE(REPLACE(@str, CHAR(13), ''), CHAR(10), '')

Let's try and compare the result with the above image.


Now, there is no more newline (enter) character.

Post a Comment

0 Comments