Add carriage return inside a varchar variable

Posted on 2005-04-29
Last Modified: 2010-03-19
I'm defining a varchar variable in a stored procedure and it would be easier to read if I could insert carriage returns into the variable.

Here's the variable

SET @BODY1 = @SEVERITY +  @SUBJ +  @FNAME + ' ' + @LNAME +
      ' ' + @COMPANY + ' ' + @PHONE + ' ' + @EMAIL +  @FB_DESC

@BODY1 is the @message parameter for xp_SENDMAIL so I don't know if there is another option for me.

Question by:SEANWYATT
    LVL 28

    Assisted Solution

    Try adding CHAR(13) like this:

    SET @BODY1 = @SEVERITY + CHAR(13) + @SUBJ +  CHAR(13) + @FNAME + ' ' + @LNAME +
         ' ' + @COMPANY + ' ' + @PHONE + CHAR(13) +' ' + @EMAIL + CHAR(13) + @FB_DESC
    LVL 14

    Accepted Solution

    you can insert char(13) and char(10) into your string - on most clients it will create desired effect:

    SET @BODY1 = @SEVERITY +  char(13) + char(10) + @SUBJ +  char(13) + char(10) + @FNAME + ' ' + @LNAME +
         ' ' + @COMPANY + ' ' + @PHONE + ' ' + @EMAIL +  @FB_DESC
    LVL 13

    Assisted Solution

    carriage returns is

    Author Comment

    Thanks all three!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This is my first ever Article on EE or elsewhere; therefore, please bear with me if I have some discrepancies in my writing. I read many articles and questions related to "how to pass values to SSIS packages at run-time?"  Hence, this common ques…
    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now