• GBeezy (5/28/2014)


    All,

    I have a field in AX that is NVARCHAR(30). Sometimes the value has 5 extra characters at the end and sometimes, it does not. I have been attempting to get rid of the trailing spaces and nothing has worked. What I have tried:

    1. LTRIM(RTRIM(colA)) AS ColA

    2. RTRIM(LTRIM(colA)) AS ColA

    3. RTRIM(colA) AS ColA

    4. REPLACE(colA), ' ','') AS ColA (my first argument for replace has 5 spaces)

    5. REPLACE(colA), ' ','') AS ColA

    6. REPLACE(LTRIM(RTRIM(colA))), ' ', '') AS ColA

    7. REPLACE(LTRIM(RTRIM(colA))), ' ', '') AS ColA

    8. I tried casting it to a VARCHAR and attempting all of the above and that is not working.

    I am not sure why this will not work, but if anyone can provide some insight, I would greatly appreciate it.

    My guess is they are not spaces some other non-printable character. Find on of the offending rows and try this.

    select ASCII(right(ColA, 1))

    Where ColA like 'SomeKnownValue%'

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/