RTRIM not working

  • I have a varchar field named email in which I cannot remove trailing spaces (char(32)). Neither RTRIM or REPLACE functions work. The LEN and DATALENGTH functions return 42 however there are numerous spaces after the 42nd character. If I convert the field to nvarchar the DATALENGTH function returns 84. When I use the ASCII function it identifies the trailing characters as 32. Can anyone help with his issue?

  • I've never had a problem with rtrim. How do you know that it isn't working?

    😎

  • I use the ASCII function to return the ascii characters of the string and it returns char(32) numerous times on the end of the string. When I run a REPLACE on the field the script below still returns the same rows. Below is the script I use.

    declare @position int, @string char(128)

    set @position = 1

    select @string = email from sysdba.contact where contactid = 'C6UJ9A02RNDG'

    while @position <= datalength(@string)

    begin

    select ascii(substring(@string, @position, 1)),

    char(ascii(substring(@string, @position, 1)))

    set @position = @position + 1

    end

  • Alan Frelich (8/8/2008)


    I use the ASCII function to return the ascii characters of the string and it returns char(32) numerous times on the end of the string. When I run a REPLACE on the field the script below still returns the same rows. Below is the script I use.

    declare @position int, @string char(128)

    set @position = 1

    select @string = email from sysdba.contact where contactid = 'C6UJ9A02RNDG'

    while @position <= datalength(@string)

    begin

    select ascii(substring(@string, @position, 1)),

    char(ascii(substring(@string, @position, 1)))

    set @position = @position + 1

    end

    I see the problem, @string is defined as char(128). This will pad the string with spaces.

    Edit:

    What are you try to accomplish here?

    😎

  • That was it. Stupid mistake on my part. Thank you for the help.:satisfied:

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

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