• Keith Tate (10/21/2013)


    You may have leading and/or trailing tabs instead of spaces which the trim's won't replace. You can use CHARINDEX to find CHAR(9) in a string and then use the replace function if that is the issue.

    /****** Script for SelectTopNRows command from SSMS ******/

    DECLARE @REALNAME varchar(255)

    SET @REALNAME = ' Ricki Ricardo'

    select LEN(@realname)

    select len(RTRIM(ltrim(@realname)))

    SET @REALNAME = 'Ricki Ricardo'

    select LEN(@realname)

    select len(RTRIM(ltrim(@realname)))

    CHAR(160)... the notorious and dreaded "Hard Space".

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)