Substituting white spaces, in a string, with nothing

  • 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 4 posts - 1 through 5 (of 5 total)

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