Home >Database >Mysql Tutorial >How to Insert Line Breaks into SQL Server VARCHAR/NVARCHAR Strings?

How to Insert Line Breaks into SQL Server VARCHAR/NVARCHAR Strings?

DDD
DDDOriginal
2025-01-16 15:50:12563browse

How to Insert Line Breaks into SQL Server VARCHAR/NVARCHAR Strings?

Insert newline character in SQL Server VARCHAR/NVARCHAR string

Question:

How to insert newline character in VARCHAR or NVARCHAR data type in Microsoft SQL Server?

Answer:

To insert a newline character in a VARCHAR or NVARCHAR string in SQL Server, use the following syntax:

<code class="language-sql">'带换行符的文本' + CHAR(13) + CHAR(10)</code>
  • CHAR(13) stands for carriage return (CR).
  • CHAR(10) stands for line feed (LF).

CHAR(13) and CHAR(10) combine to create a DOS/Windows-style CRLF line break, commonly used for text formatting.

Example:

To insert a newline character in the following string:

<code class="language-sql">'这是一个字符串。'</code>

Use the following statement:

<code class="language-sql">UPDATE 表 SET 文本值 = 文本值 + CHAR(13) + CHAR(10) + '这是一行新内容。'</code>

This will generate a string containing:

<code>'这是一个字符串。
这是一行新内容。'</code>

The above is the detailed content of How to Insert Line Breaks into SQL Server VARCHAR/NVARCHAR Strings?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn