SQL Server Performance

[Solved]Removing or replacing all end of line character from a string

Discussion in 'SQL Server 2005 General Developer Questions' started by Dale L, Aug 6, 2007.

  1. Dale L New Member

    Hello all,
    Im looking for an efficient way to remove all end of line character from a string.
    Is there a function to do that or to replace them with another character?
  2. dineshasanka Moderator

    REPLACE ( 'string_expression1' , 'string_expression2' , 'string_expression3' )
  3. Adriaan New Member

    Just note that usually end-of-line is marked by two characters together, carriage-return and line-feed (CRLF). In ASCII code, that's characters 13 and 10, or in T-SQL it's CHAR(13) + CHAR(10).
    So the REPLACE call will go something like:
    REPLACE(expression, CHAR(13) + CHAR(10), ' ')
    ... which replaces the CRLF with a blank.
    In case you have legacy data ('old' data) it never hurts to check if there are individual CHAR(13)s or CHAR(10)s.

Share This Page