Formatting Text with Line Breaks in SQL Server VARCHAR/NVARCHAR Strings
Working with text data in SQL Server often requires precise formatting. This article explains how to add line breaks to VARCHAR and NVARCHAR strings for improved readability.
The Solution: Using CHAR(13) and CHAR(10)
To insert a line break, utilize the CHAR(13)
function, representing the carriage return (CR) character, common in DOS/Windows systems. For complete CRLF line breaks (carriage return and line feed), use this formula:
<code class="language-sql">CHAR(13) + CHAR(10)</code>
Here's an example demonstrating how to add a line break between two lines of text:
<code class="language-sql">'This is the first line.' + CHAR(13) + CHAR(10) + 'This is the second line.'</code>
This method ensures correct line breaks, enhancing the display and presentation of your text data within SQL Server applications. The resulting string will display with properly formatted lines when retrieved.
The above is the detailed content of How Do I Add Line Breaks to VARCHAR/NVARCHAR Strings in SQL Server?. For more information, please follow other related articles on the PHP Chinese website!