Skip to main content

Replace or remove all line breaks (or new lines) from a column.

--
-- | Control Character | T-SQL Reprentation | Abbreviation | Escape code |
-- |-------------------|--------------------|--------------|-------------|
-- | Horizontal Tab    | char(9)            | HT           | \t          |
-- | Line Feed         | char(10)           | LF           | \n          |
-- | Carriage Return   | char(13)           | CR           | \r          |
--

-- To replace line-breaks with a single space:
select replace(replace(@str, char(13), ' '), char(10), ' ');

-- To remove all line breaks:
select replace(replace(@str, char(13), ''), char(10), '');

-- To replace Windows line-breaks with a space:
select replace(@str, char(13) + char(10), ' ');

-- To show ascii character code:
declare @str varchar(max) = '	'; -- tab
select 'char('+ cast(ascii(@str) as varchar(10))+')' as AsciiCode;
-- AsciiCode
-- char(9)