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) 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!