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

How to Add Line Breaks to SQL Server VARCHAR/NVARCHAR Strings?

Susan Sarandon
Susan SarandonOriginal
2025-01-16 15:37:10869browse

How to Add Line Breaks to SQL Server VARCHAR/NVARCHAR Strings?

Inserting Line Breaks into SQL Server VARCHAR/NVARCHAR Strings

Question: How can I correctly add line breaks to VARCHAR or NVARCHAR strings in SQL Server?

A developer recently faced this challenge and found limited readily available solutions.

Answer: SQL Server uses character codes to represent line breaks. For the standard DOS/Windows line break (CRLF - carriage return and line feed), use this code:

<code class="language-sql">CHAR(13) + CHAR(10)</code>

Here's how to use it to create a multi-line string:

<code class="language-sql">'This is the first line.' + CHAR(13) + CHAR(10) + 'This is the second line.'</code>

The above is the detailed content of How to Add Line Breaks to 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