Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SSIS Derived Column split first parentheses of characters

Status
Not open for further replies.

Broadleon

IS-IT--Management
Mar 12, 2014
1
GB
Im trying to workout how to write an expression in the derived Column task, to extract a readcode e.g (XXXX) from another column

ID | Ethnicity | ReadCode
-------------------------------------
1 | (XXXX) White British | (XXXX)

So far i have the expression
Code:
"(" + SUBSTRING(Ethnicity,(FINDSTRING(Ethnicity,"(",1) + 1),(FINDSTRING(Ethnicity,")",1) - 2))

But it throws up an error:

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

[Derived Column 2 [11]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Derived Column 2" failed because error code 0xC0049067 occurred, and the error row disposition on "Derived Column 2.Inputs[Derived Column Input].Columns[ReadCode]" 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.

[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Derived Column 2" (11) failed with error code 0xC0209029 while processing input "Derived Column Input" (12). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.

Can anyone help?
 
2 things wrong there.

1 - it will fail if the string does not contain both ( and ) in that order - look at using the if operator before doing the string.

2 - SUBSTRING(Ethnicity,(FINDSTRING(Ethnicity,"(",1) + 1),(FINDSTRING(Ethnicity,")",1) - 2))
is incorrect. lets look at this example.
string = "XXX ( CC )" - e.g. string with 9 chars in size.
the above formula would return SUBSTRING(string, 5 + 1, 9 - 2) - this would fail as 6 , 7 results on a substring bigger than the remaining number of characters on your string.
so correct formula would be SUBSTRING(Ethnicity,(FINDSTRING(Ethnicity,"(",1) + 1),(FINDSTRING(Ethnicity,")",1) - FINDSTRING(Ethnicity,"(",1)) )) (or very near, but you should get the idea)



Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top