Remove new line char from a varchar field.

  • I have a field(varchar) where there are new line chars throughout. Is there a replace statement which can remove the chars from this field?  Or is there a way to find\identify the NL chars using sql?

    Thank you.
    Francis S. Mazeika
    MS SQL DBA
    609-707-5207
    francis.mazeika@gmail.com

  • UPDATE YourTable

    SET YourCol = REPLACE(YourCol, CHAR(13) + CHAR(10), '')

    --
    Adam Machanic
    whoisactive

  • Thank you very much it worked!

    Thank you.
    Francis S. Mazeika
    MS SQL DBA
    609-707-5207
    francis.mazeika@gmail.com

  • Just adding to the brain dump, this worked very well, I found I had some line feeds to.

    These steps cleaned it all out.

    UPDATE mytable

       SET myfield = REPLACE(myfield, CHAR(9), '') WHERE CHARINDEX(CHAR(9), myfield) <> 0

    UPDATE mytable

       SET myfield = REPLACE(myfield, CHAR(10), '') WHERE CHARINDEX(CHAR(10), myfield) <> 0

    UPDATE mytable

       SET myfield = REPLACE(myfield, CHAR(13), '') WHERE CHARINDEX(CHAR(13), myfield) <> 0

    Thanks for your lead on this

    Thank you.
    Francis S. Mazeika
    MS SQL DBA
    609-707-5207
    francis.mazeika@gmail.com

  • How do you this with a text column field? Can't use replace.

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

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