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

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

DDD
DDDOriginal
2025-01-16 15:44:18907browse

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

Insert newline character in SQL Server VARCHAR/NVARCHAR string

While this topic may not have been mentioned explicitly in previous discussions, it is an issue developers often encounter. To solve this problem, let us explore the solution to insert newline character in VARCHAR/NVARCHAR strings in SQL Server.

Solution:

To insert a newline character in a VARCHAR/NVARCHAR string, you can use the following characters:

  • char(13): The carriage return (CR) character represents the end of a line in DOS-based systems.
  • char(10): The linefeed (LF) character indicates the beginning of a new line in UNIX-based systems.

For DOS/Windows-conforming newlines (CRLF), combine char(13) with char(10) as follows:

<code class="language-sql">'这是第一行。' + CHAR(13) + CHAR(10) + '这是第二行。'</code>

By adding these characters, you effectively create newlines in VARCHAR/NVARCHAR strings in SQL Server.

The above is the detailed content of How Do I 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