How to remove Carriage Return from string?

  • How can I remove Carriage Return -> char(13)

    from a normal string

    in tsql because I don't succeed with the replace function eg.

    SELECT REPLACE(CHAR(13), mystring, '')

  • you have the parameters switched wrong

    also it might be a good idea to out the newline character too

    REPLACE(REPLACE(mystring,CHAR(13),''),CHAR(10),'')

  • Thanks a lot for that information,

    I switched my parameter wrong here but not in the actual try but you are right it was because of the line feed : char(10)

  • This is fine but it removes all carriage returns and linefeeds, even ones you want to keep... Is there a solution for this?

    SET line1 = 'line1'

    SET line2 = 'line2'

    SET lines = line1 + CHAR(13) + CHAR(10)

    SET lines = lines + line2 + CHAR(13) + CHAR(10)

    SET lines = REPLACE(REPLACE(lines, CHAR(13),''), CHAR(10),'')

    lines = line1line2

    not ...

    line1

    line2

Viewing 4 posts - 1 through 3 (of 3 total)

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