Removing char after space

  • All,

    I have data coming in a column in the following format

    02968-01999-00013 - 9.The length of the data is not fixed,but 1 thing for sure is the last 4 char of the data consist of ' - 9'.I need to come up with the best way to get rid of the last 4 char of the data coming in.I have a table with 50 000 rows and this figure is going to increase over time.What is the fastest way to do this and be able to implement it in SSIS ?

  • SELECT SUBSTRING('02968-01999-00013 - 9',1,CHARINDEX(' ','02968-01999-00013 - 9')-1)

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

  • Thanks Jeff,

    How can I accomplish this in SSIS? ...as the script required passing the value of data each time.Is there anyway to pass the column name instead ?

  • Yes... just sub a column name in the place of the string literal in both places.

    So far as exactly how to do it in SSIS, I don't know because I do all my ETL using T-SQL... I don't even know how to spell "SSIS".

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

  • p.s. You may have better luck if you posted this on the SSIS forum.

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

  • Thanks Jeff, I shall do that.

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

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