Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace a newline in TSQL

Tags:

tsql

newline

I would like to replace (or remove) a newline character in a TSQL-string. Any Ideas?

The obvious

REPLACE(@string, CHAR(13), '') 

just won't do it...

like image 990
Peter Avatar asked Jun 04 '09 16:06

Peter


People also ask

How do you change a line break in SQL Server?

Remove and Replace Carriage Returns and Line Breaks in SQL Using SQL to remove a line feed or carriage return means using the CHAR function. A line feed is CHAR(10); a carriage return is CHAR(13).

How do you find and replace in newline?

On the keyboard, press Ctrl + H to open the Find and Replace dialog box, with the Replace tab active. On the Replace tab, click in the Find What box. On the keyboard, press Ctrl + J to enter the line break character.


2 Answers

Actually a new line in a SQL command or script string can be any of CR, LF or CR+LF. To get them all, you need something like this:

SELECT REPLACE(REPLACE(@str, CHAR(13), ''), CHAR(10), '') 
like image 108
RBarryYoung Avatar answered Sep 20 '22 13:09

RBarryYoung


REPLACE(@string, CHAR(13) + CHAR(10), '') 
like image 41
Mitch Wheat Avatar answered Sep 18 '22 13:09

Mitch Wheat