substitute line breaks for

  • 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

  • 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.

  • 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

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

    John

  • 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.

    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 4 (of 4 total)

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