Skip to content
Fix Code Error

How to insert a line break in a SQL Server VARCHAR/NVARCHAR string

March 13, 2021 by Code Error
Posted By: Mark Struzinski

I didn’t see any similar questions asked on this topic, and I had to research this for something I’m working on right now. Thought I would post the answer for it in case anyone else had the same question.

Solution

I found the answer here: http://blog.sqlauthority.com/2007/08/22/sql-server-t-sql-script-to-insert-carriage-return-and-new-line-feed-in-code/

You just concatenate the string and insert a CHAR(13) where you want your line break.

Example:

DECLARE @text NVARCHAR(100)
SET @text = 'This is line 1.' + CHAR(13) + 'This is line 2.'
SELECT @text

This prints out the following:

This is line 1.
This is line 2.

Answered By: Mark Struzinski

Related Articles

  • Reference - What does this regex mean?
  • Azure SQL SCOPE_IDENTITY to create identical ID columns for…
  • Log record changes in SQL server in an audit table
  • How to parse an RSS feed using JavaScript?
  • SQL NVARCHAR and VARCHAR Limits
  • sql query to find priority jobs
  • How do I include certain conditions in SQL Count
  • How to Replace Multiple Characters in SQL?
  • Local variable referenced before assignment?
  • Generate SQL Create Scripts for existing tables with Query

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Can I have an onclick effect in CSS?

Next Post:

How do I update pip itself from inside my virtual environment?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error