I have a criteria where I need to extract Year from the File Name
The File name will be in following way
FILE.TEST.ASSGN_2012_Retro_Year Result should be 2012
FILE.TEST.ASSGN_2013_Retro_Year Result should be 2013
FILE.TEST.ASSGN_2014_Retro_Year Result should be 2014
I am extracting the file name to the Variable called as FileName
I tried below expression in derived column but no luck:
SUBSTRING(#[User::FileName], FINDSTRING(#[User::RealFileName], "HASSN_",1,4))
You have several typos and improper usage in your current expression.
Try the following Expression. It works.
SUBSTRING( #[User::RealFileName],FINDSTRING(#[User::RealFileName], "ASSGN_",1)+6,4)
In my test, I created a variable called RealFileName and assigned it your 1st test value of FILE.TEST.ASSGN_2012_Retro_Year.
Then I created a variable called FileName and assigned it the expression
SUBSTRING( #[User::RealFileName],FINDSTRING(#[User::RealFileName], "ASSGN_",1)+6,4)
See what the Evaluated value expression shows for this test value.
Related
I want to add the date of last day of current month using expression builer in SSIS
Since it is march
I want the file name to be XXXXXX20210331.csv
This approach comes to mind and may be useful with your overall design and avoiding complex expressions:
First generate an Execute SQL Task with a "single row" result set.
Add this to the SQLStatement:
SELECT CONVERT(VARCHAR(8),EOMONTH(GETDATE()),112) as [Date]
Set the Variable Name in the result set to a user variable (that you will need to create "date") and add "Date" to the result name section
When ready to config your Flat File Destination Connection Manager/String:
Using the Expression Builder in the Flat File Connection (go to properties to set a variable --> Connection String for the Flat File Destination.
That said, you will need a working connection string and need to make it dynamic.
Add to the expression:
"filepath" + "XXXXXX" + (DT_STR, 8, 1252) #[User::date] + ".csv"
Hit "Evaluate value" to double check the full file path to be used in your destination with dynamic file name
SSIS expression is written for the Flatfile location.Th is a variable and the value is hardcoded.
Example
#varFileLoc
"\\\\server\\folder1\\folder2\\folder3\\" + #[User::varDFolder]
this variable value has been passed to a a FEL.When tried in debiugg mode I can see the value of the variable is
\\\\server\\folder1\\folder2\\folder3\\folder4\\
instead of
\\server\folder1\folder2\folder3\folder4\
what might be the reason for this
I have a pretty simple package. It reads a flat file, extracts date from a header record and subsequently uses derived column component to reformat data to the desired output format. One of the columns (FileRunDate, string, length 8) in the derived component is defined as a string and in the expression I'm assigning it to a variable I set earlier in the script component - #[User::vRunTimeDate]. When the process runs, the output file gets generated, however FileRunDate is blank. The default value of the variable is blank, however if I were to set it to some date, then the output file does reflect this value. It seems that the variable assignment in the script task does not work, but if I were to debug it, then I see how the value is being set. The variable has an attribute of ReadWrite.
Any feedback is greatly appriciated.
I am trying to add the following expression to a TextBox on a Report Builder report using the following code:
=SUM(IIF(Fields!TaskDescription.Value,"DataSet1") = "Running", 1, 0)
I have more than 1 dataset which I think is causing the issue, but the above gives me the following error message:
The scope parameter must be set to a string constant that is equal to
either the name of a containing group, the name of a containing data
region, or the name of a dataset.
What am I doing wrong?
The Scope, in your case the DataSet, need to be the last parameter in the aggregate, i.e. after the IIf:
=SUM(IIF(Fields!TaskDescription.Value = "Running", 1, 0), "DataSet1")
i.e. =Sum(<Expression>, <Scope>)
The expression counts the occurrences of the value Running in the TaskDescription column in the DataSet1 DataSet.
Edit after comment
A quick test showing the expression in action. A simple DataSet with your column:
I've just added a textbox to a blank report with the above expression:
Works as expected on the sample data:
I have an Excel Source which has got 1000 rows with some 10 columns and one of the column is a Date Field ,We have to retrieve the minimum date value and assign it to a variable in ssis .Could you guys provide me a script or steps to map that value to the variable...So that i can use it in control flow task to perform truncate operation using the variable value.
please adviiiise
your help in this regard is appreciated.
Rosh..
It's fairly simple: you use an Execute SQL Task to retrieve the value and store it in a variable.
Basic steps:
A. Create an Excel Connection Manager, point it at your file
B. Create a variable to store the value
C. Add an Execute SQL Task
Connection type: EXCEL
Specify connection manager
ResultSet: single row
SQLSourceType: Direct input
SQLStatement: select max(fieldname) as fieldname from [sheetname$]
In the result set tab, add a row with the the ResultName set to fieldname, and the earlier created variable in the Variable Name column.
Note that the sheetname qualification (square brackets) is necessary because of the required $. If your field (column) contains a space in the name, you have to also qualify it: [field name]