Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SubString


SubString

Author
Message
Paul_Harvey
Paul_Harvey
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 354
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
tej3as
tej3as
SSC Journeyman
SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)

Group: General Forum Members
Points: 76 Visits: 113
SUBSTRING within Derived Column is ur answer. try using sequence of substrings to achieve this.
Paul_Harvey
Paul_Harvey
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 354
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
Paul_Harvey
Paul_Harvey
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 354
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
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16447 Visits: 13202
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))





How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Paul_Harvey
Paul_Harvey
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 354
Really? I thought the third argument specified how many characters to use.

SUBSTRING(fieldname,start_position, number of characters)

I'll look into this.
Paul_Harvey
Paul_Harvey
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 354
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
Paul_Harvey
Paul_Harvey
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 354
Thanks for your help on this one, Da Zero.
Great advice!

Paul
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16447 Visits: 13202
No problem at all!
I'm glad to help.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search