substitute line breaks for

  • mick burden

    SSCarpal Tunnel

    Points: 4432

    is it possible to change any line breaks or newlines for a string

    in a select statement in a store procedure, in this way I can reproduce text in a label on a webpage complete with line breaks

  • mick burden

    SSCarpal Tunnel

    Points: 4432

    I've tried the following

    SELECT ROW_NUMBER() OVER

    (

    ORDER BY [recid] desc

    )AS RowNumber

    ,[recid]

    ,REPLACE(REPLACE(text1, CHAR(13), '<br >'), CHAR(10), '<br >')

    ,[dte]

    INTO #Results

    text1 is a text field, the error I'm getting is :

    Msg 1038, Level 15, State 5, Procedure GetCustomersPageWise, Line 9

    An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.

  • mick burden

    SSCarpal Tunnel

    Points: 4432

    With help from a colleague I've come up with the following that works.

    SET NOCOUNT ON;

    SET DATEFORMAT dmy;

    SELECT ROW_NUMBER() OVER

    (

    ORDER BY [recid] desc

    )AS RowNumber

    ,[recid]

    ,REPLACE(REPLACE(text1, CHAR(13), '<br >'), CHAR(10), '<br >') as text1

    ,[dte]

    INTO #Results

  • John Mitchell-245523

    SSC Guru

    Points: 148546

    The answer's right there in the error message. You don't have an alias for the third column of your SELECT statement.

    John

  • Jeff Moden

    SSC Guru

    Points: 995523

    mick burden (8/17/2015)


    With help from a colleague I've come up with the following that works.

    SET NOCOUNT ON;

    SET DATEFORMAT dmy;

    SELECT ROW_NUMBER() OVER

    (

    ORDER BY [recid] desc

    )AS RowNumber

    ,[recid]

    ,REPLACE(REPLACE(text1, CHAR(13), '<br >'), CHAR(10), '<br >') as text1

    ,[dte]

    INTO #Results

    That can very easily lead to double spacing. I've seen files with CrLf and files with just Lf. I've not see files with just Cr. So, the replace line should probably change Cr to nothing and just work with the Lf. Like this...

    ,REPLACE(REPLACE(text1, CHAR(13), ''), CHAR(10), '<br >') as text1

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply