Derived Column condition to get string between two Hyphens
Asked By: Catalyst
Originally Asked On: 2014-01-02 12:02:48
Asked Via: stackoverflow
I need an SSIS expression to get the left part of a string before the separator, and then put the new string in a new column. I checked in derived column, it seems no such expressions. “Substring” could only return string part with fixed length. For example, with separator string ‘-‘ :
input :
MQ-240030-Black
expected output :240030
my attempt :
SUBSTRING(name,1,FINDSTRING(name,"-",1) - 1)
He received 2 answers
without selecting any answers.
If the selected answer did not help you out, the other answers might!
All Answers For: Derived Column condition to get string between two Hyphens
BhupeshC’s answer to
Derived Column condition to get string between two Hyphens
Change the Expression to
SUBSTRING(name,FINDSTRING(name,"-",1) + 1,FINDSTRING(name,"-",2) - FINDSTRING(name,"-",1) - 1)
EDITED
substring
name
from the index after the first occurrence of hyphen (FINDSTRING(name,"-",1) + 1
) to the index before the second occurrence of hyphen (FINDSTRING(name,"-",2) - FINDSTRING(name,"-",1) - 1
)EDITED AGAIN
To get “BLACK” as output
substring
name
from the index after the second occurrence of hyphen (FINDSTRING(name,"-",2) + 1
) to the last index (LEN(name)
) So, it will beUPPER(SUBSTRING(name,FINDSTRING(name,"-",2) + 1,LEN(name)))
I included
UPPER()
as I see the result string in Upper cases.
Justin’s answer to
Derived Column condition to get string between two Hyphens
Code:
SUBSTRING(name,FINDSTRING(name,"-",1) + 1,FINDSTRING(name,"-",2) - FINDSTRING(name,"-",1) - 1)
Result:
name name2 MQ-240030-Black 240030
Of course, you should really check out the original question.
The post Derived Column condition to get string between two Hyphens appeared first on Tech ABC to XYZ.