SubString

  • I have a field in my SSIS package formatted as follows:

    5/3/233634$00

    5/2/126902$00

    1/64/78326$01

    5/52/66352$01

    1/172/503570$01

    1/126/99955$01

    1/172/503571$01

    9/7/44633$01

    3/23/38300$01

    3/10/43869$01

    1/52/157940$01

    1/126/99956$01

    1/171/200563$01

    I need to split this into three fields:

    Field 1 - The digit(s) to the left of the FIRST "/"

    Field 2 - The digit(s) BETWEEN the two "/"s

    Field 3 - The digits between the SECOND "/2 and the "$"

    Try as I might, I cannot get this to work on my Derived Column transformation.

    Can someone please help?

    Paul

  • SUBSTRING within Derived Column is ur answer. try using sequence of substrings to achieve this.

  • I have tried the following:

    For Field 1 - SUBSTRING([RefNumber],1,1)

    This correctly returns the first digit.

    For Field 3 - SUBSTRING([RefNumber],FINDSTRING("/",[RefNumber],3),(FINDSTRING("$",[RefNumber],3)) - FINDSTRING("/",[RefNumber],3))

    This is accepted by the Derived COlumn transformation, but when I debug the package it fails with the following:

    [Derived Column [4862]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "component "Derived Column" (4862)" failed because error code 0xC0049067 occurred, and the error row disposition on "output column "Derived Column 1" (10186)" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.

    [Derived Column [4862]] Error: An error occurred while evaluating the function.

    Can anyone help me please?

    Paul

  • An update:

    I now have this functionality working in T-SQL.. bu tI would dearly LOVE to have the expression in the Derived Column do this job.

    In T-SQL I am using the following:

    select

    RefNumber,SUBSTRING(RefNumber, 1, (CHARINDEX('/',[RefNumber],1 )-1)) as Store,

    SUBSTRING([RefNumber],(CHARINDEX('/',[RefNumber],1 )+1),(CHARINDEX('/',[RefNumber],4)) - (CHARINDEX('/',[RefNumber],1)+1)) as Till,

    SUBSTRING([RefNumber],(CHARINDEX('/',[RefNumber],4 )+1),(CHARINDEX('$',[RefNumber],4)) - (CHARINDEX('/',[RefNumber],4)+1)) as Trans_Num

    from imported_data

    select

    SUBSTRING([RefNumber],(CHARINDEX('/',[RefNumber],1 )+1),(CHARINDEX('/',[RefNumber],3)) - (CHARINDEX('/',[RefNumber],1)+1)) as Trans_Num

    from RefTable

    which is returning the data in the format I'd like it.

    Can anyone give me a pointer?

    Paul

  • Paul_Harvey (2/24/2010)


    For Field 3 - SUBSTRING([RefNumber],FINDSTRING("/",[RefNumber],3),(FINDSTRING("$",[RefNumber],3)) - FINDSTRING("/",[RefNumber],3))

    This is accepted by the Derived COlumn transformation, but when I debug the package it fails with the following:

    [Derived Column [4862]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.

    The 3rd argument of Findstring specifies which occurrence of the 2nd argument you want. You've placed the number 3 there for backslash, but I only count 2 for backslash and also 3 for $, but I only see one.

    Try:

    SUBSTRING([RefNumber],FINDSTRING("/",[RefNumber],2),(FINDSTRING("$",[RefNumber],1)) - FINDSTRING("/",[RefNumber],2))

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Really? I thought the third argument specified how many characters to use.

    SUBSTRING(fieldname,start_position, number of characters)

    I'll look into this.

  • My apologies. I didn't read properly!

    You are refering to FINDSTRING, not SUBSTRING.

    Thanks for the pointer. I'll give it a go.

    Paul

  • Thanks for your help on this one, Da Zero.

    Great advice!

    Paul

  • No problem at all!

    I'm glad to help.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 9 posts - 1 through 8 (of 8 total)

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