You must Sign In to post a response.
  • Category: SQL Server

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

    I have a string like this.
    N'Your password has just been reset successfully. If you did not reset your password, please log in and ensure your password is secure and up to date.MyLincoln Mobile Team'

    but I need like below format.

    Your password has just been reset successfully. If you did not reset your password, please log in and ensure your password is secure and up to date.

    MyLincoln Mobile Team

    field name is body
    data type is nvarchar(max)
    Please.. suggest me aSAP.
  • #764243
    Hi bujji,

    You need to add CHAR(13) between your two string.

    DECLARE @text NVARCHAR(max)
    SET @text = 'Your password has just been reset successfully. If you did not reset your password, please log in and ensure your password is secure and up to date.' + CHAR(13) + 'MyLincoln Mobile Team'
    print @text

    Hope this will help you.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764253
    When you store any string in database it will not store any line break in database, instead you can put \r\n in string, and then you can put it in database, so when you load your string in any control it will show line break automatically.
    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764271
    Hai Bujji,
    You can use the + CHAR(13)+CHAR(10) + as the concatenation between your string to get the line break.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764292
    Hi,

    Apart from the above 3 solutions you can store <br/> between 2 strings, when you are handling the string using html tags, this will shows the result with different line.

    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #764338
    declare @str nvarchar(4000)
    set @str = N'Your password has just been reset successfully. If you did not reset your password, please log in and ensure your password is secure and up to date.MyLincoln Mobile Team'
    print @str

    declare @str1 nvarchar(4000)
    set @str1 = N'Your password has just been reset successfully. If you did not reset your password, please log in and ensure your password is secure and up to date.'+ CHAR(13) +'MyLincoln Mobile Team'
    print @str1

    Cheers,
    Venkatesan Prabu .J
    SQL Server MVP


Sign In to post your comments