Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert a line break in a SQL Server VARCHAR/NVARCHAR string

I didn't see any similar questions asked on this topic, and I had to research this for something I'm working on right now. Thought I would post the answer for it in case anyone else had the same question.

like image 346
Mark Struzinski Avatar asked Aug 27 '08 19:08

Mark Struzinski


People also ask

How do you add a line in SQL?

Basic INSERT syntax Here is the basic syntax for adding rows to a table in SQL: INSERT INTO table_name (column1, column2, column3,etc) VALUES (value1, value2, value3, etc); The first line of code uses the INSERT statement followed by the name of the table you want to add the data to.

What is CR LF in SQL?

Removing a Carriage Return, Line Feed (CRLF) from a Column in SQL Server. The term CRLF refers to Carriage Return (ASCII CHAR(13), \r) Line Feed (ASCII CHAR(10), \n).


1 Answers

char(13) is CR. For DOS-/Windows-style CRLF linebreaks, you want char(13)+char(10), like:

'This is line 1.' + CHAR(13)+CHAR(10) + 'This is line 2.' 
like image 153
Sören Kuklau Avatar answered Sep 21 '22 08:09

Sören Kuklau