Trim Function help

  • Hi Guys,

    I have question regarding Trim function,

    Here is my requirement,

    Address = ADDRESS1+ADDRESS2+ADDRESS3

    I want to trim if there is no Address1 or Address3

    I know i can use Ltrim & Rtrim function, Could you please anyone can help me how i can use trim function in TSql and SSIS. Thanks in advance.

  • rocky_498 (2/26/2011)


    Hi Guys,

    I have question regarding Trim function,

    Here is my requirement,

    Address = ADDRESS1+ADDRESS2+ADDRESS3

    I want to trim if there is no Address1 or Address3

    I know i can use Ltrim & Rtrim function, Could you please anyone can help me how i can use trim function in TSql and SSIS. Thanks in advance.

    Address = RTRIM(LTRIM(ADDRESS1+ADDRESS2+ADDRESS3))

  • rocky_498 (2/26/2011)


    Hi Guys,

    I have question regarding Trim function,

    Here is my requirement,

    Address = ADDRESS1+ADDRESS2+ADDRESS3

    I want to trim if there is no Address1 or Address3

    I know i can use Ltrim & Rtrim function, Could you please anyone can help me how i can use trim function in TSql and SSIS. Thanks in advance.

    If the addresses are VARCHAR and are NULL when missing, then the following will work just fine...

    SELECT RTRIM(ISNULL(Address1 + ' ','') + ISNULL(Address2 + ' ','') + ISNULL(Address3,''))

    --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)

Viewing 3 posts - 1 through 2 (of 2 total)

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