Tuesday, March 11, 2014

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

There are some scenarios where we need to put line breaks in the string we write back from procedure or any dynamic SQL we use.

Here is how we can do this by adding CHAR(13) or CHAR(10) in between the string we write back. This will insert carriage return(code 13) or newline feed(code 10) in the text leading to the text format as you are trying to get.

DECLARE @ReturnMsg NVARCHAR(100)
SET @ReturnMsg = 'Missing state information.' + CHAR(13) + 'This is Address line 1.'
SELECT @ReturnMsg

1 comment:

  1. Having read this I believed it was rather informative.

    I appreciate you spending some time and effort to
    put this information together. I once again find myself personally spending a significant amount of time both reading
    and posting comments. But so what, it was still worthwhile!


    Check out my web blog; Facial Products

    ReplyDelete