Substituting white spaces, in a string, with nothing

  • I can't find the answer to this question, although I know that I have asked it before. Appologies for repeating the question.

    I wish to substitue the white space in a string with nothing. So that a statement like :

    WHERE O.Postcode_no_spaces = D.Postcode_8

    reads:

    ...............WHERE O.Postcode_no_spaces = D.Postcode_8

    ....where D.Postcode_8 has had the white spaces removed.

  • Would that be the REPLACE function you were thinking of?

    WHERE O.Postcode_no_spaces = REPLACE(D.Postcode_8, ' ', '')

  • You can also do a RTRIM(LTRIM(.....)), this will eliminate any white space.

  • Loner (1/7/2008)


    You can also do a RTRIM(LTRIM(.....)), this will eliminate any white space.

    RTRIM(LTRIM(.....)) will eliminate only leading and trailing spaces, not the ones in the middle of the string.

    _____________
    Code for TallyGenerator

  • Watch out for embedded carriage returns, tabs, etc...

    RTRIM(LTRIM()) and REPLACE(string,' ','') will not clean it all up.

    I don't have the full list at hand, mine is an Oracle version.

    Obvious ones to keep in mind are:

    REPLACE(string,char(10),'') -- Line Feed

    REPLACE(string,char(13),'') -- Carriage return

    REPLACE(string,char(9),'') -- Tab

    You can string them together like:

    select RTRIM(LTRIM(REPLACE(REPLACE(REPLACE(REPLACE(MyStrColumn,char(13),''),char(10),''),char(9),''),' ',''))) as MyStrColumn

    from MyTable

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

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