Monday 6 February 2023

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

 

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

 

 

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.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Blog Archive