Logging Experiences

T-SQL: remove or replace line breaks

Posted in Programming, SQL, Tips and Tricks by Sina Iravanian on September 6, 2012

Sometimes you might need to remove line breaks from a column value to make a one-line data. I prefer to replace line-breaks with a single space, rather than removing them. This is how to do it with Transact-SQL:

REPLACE(REPLACE(ISNULL( SomeTable.SomeColumn, ''), CHAR(13), ''), CHAR(10), ' ')

To remove line-breaks completely replace the final space string with an empty string.

Tagged with: ,