I need help for below scenario.
I have file names like this
abc_assessment_20200303121212.csv
fgcdv_assessment_20200303121212.csv
xycv_assessment_20200303121212.csv
Now I need to right expression into SSIS package to identify files which contains "assessemnt" as keyword.
I used below expression but it didn't work
substring( @[User::FileName],1, FINDSTRING( @[User::FileName],"_",2)-1)=="assessment"
There is no debugging capability in the SSIS Expression language. Therefore, when you don't write a complex expression correctly the first time, it's an indicator you're doing too much in one step.
Let's break down your expression.
In the innermost operation, you are using findstring to find the position of the second underscore
FINDSTRING( @[User::FileName] ,"_",2)
If FileName is xycv_assessment_20200303121212.csv that would yield a value of 16.
How did I know this? I created a variable called SecondUnderscore and it is simply the Findstring operation.
Building on that, I create a second variable called SubString which uses the SecondUnderscore variable
substring( @[User::FileName],1, @[User::SecondUnderscore] -1)
I see quite clearly that my value is "xycv_assessment"
This operation compares the results of SubString to my sentinel value of assessment.
@[User::SubString] == "assessment"
It still yields a False as xycv_assessment is clearly not the same as assessment.
String comparison is case sensitive so be aware that Assessment will not match assessmenT etc. The Lower() expression will help avoid that situation
If you need to find the pieces xycv vs asessment vs date string, then keep going this route but find the place of your first underscore and slice the pieces out.
Otherwise, take @Tyron78's example and just check for the presence of the string assessment. If findstring is greater than zero, it's in the file name.