tsql - Expression to look up certain character and store it in SSIS variable -
In SSIS 2008, I have a variable called
@ [User: EANcode] contains a string in it.
'1234567891123' with a product like Encore. The value is derived from a filename such as '1234567891123.jpg' via a foreach loop. However, sometimes files like '1234567891123_1.jpg' have an additional '_1', '_2' etc., which results in '1234567891123_1' in the EANcode variable.
This happens when there is more than one image for the same ENAXode (product). The _n addition is always a number and it always happens at the end of the name / string.
What is the expression to find the '_1' (or_2 or_ N etc) Kaith, so that you can store it in another variable named @ [User :: Addition] < / code>? If there is no extra, then the variable remains empty which is fine.
Because of this, I need to get this extra _N in a different variable that I need to rename the file name later, but eventually paste the pair.
Thank you!
I think you are searching for CHARINDEX ()) Combined with SUBSTRING () . With it, you can split that # into another variable (copy / pasta and execute to see. Play with the @ Temp1 variable to see the limitations of the game): Declare @ temp1 varchar (20), @ temp2 varchar (20) set @ temp1 = '1234567891123_12' if CHARINDEX ('_', @ temp1) & gt; 1 set @ temp2 = SUBSTRING (@ temp1, CHARINDEX ('_', @ temp1), lan (@ temp1) -CHARINDEX ('_', @ temp1) +1) @ temp1, @ temp2 Hope it helps!
Comments
Post a Comment