ssis expression file path - ssis

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

Related

dynamic variable keeps recalculating (datetime for filename)

I have a problem in a small SSIS package that I'm trying to do for storing a query result into an excel file
I want the file to have a dynamic name of Missing_Timecards_#DATETIME#.xlsx
for example: "Missing_Timecards_20220808_131321.xlsx"
for this I have created a template file that has the columns and sheet name I want.
and I have set a system task to copy this template file into a new one with the dynamic name I want to have:
for the variables I have set a combination of a few fields to get my dynamic filename with the date:
the expression for getting the date is
REPLACE(REPLACE( REPLACE(SUBSTRING((DT_WSTR,50)GETDATE(),1,19),"-",""),":","")," ","_")
so far so good, no errors here, when the process starts the variable gets calculated, the filetask creates a copy with the freshly calculated field and goes to the dataflow that retrieves the data and saves it into the excel file path set with the variable that was calculated originally for the filename+datetime
However here is where the issue appears, it seems that the variable is calculated again, so a new file gets created with a "fresh" datetime part of the name, and as the sheet name doesn't match it gives an error.
I think the issue is that is calculating the variable again, how do I stop this from happening? (I have set delay validation = true in for the excel connection and the dataFlow)
As you've identified, GETDATE() is calculated each time it is evaluated. Instead, I favor using a System scoped variable like #[System::StartTime] as it is the time the package started execution but remains constant for the duration of the package.
Literally, swap reference to getdate() with #[System::StartTime] and you're set.
The other option is to
Copy the existing expression to your clipboard
Clear the expression from the Variable
Add an Expression Task to the Control Flow and re-use the expression in the clipboard to assign the value to your #[User::DateTime] variable
Personally, I favor the former approach as a consultant because I still run into SQL Server 2008/R2 packages and the Expression Task was not available for the product.

Change system variables length in SSIS

I have source excel file and I need to add the file name to every row, When I select the file name from system variables, the system set 0 as the length. How could I change this value?
This is typically done in the data flow with a derived column.
Simply add a column of type string and set the expression to the filename of your excel file (typically through a variable).

SSIS: Read property from another component?

I created a simple SSIS job that exports a sql table to a text file. Since the filename's dynamic, I set the ConnectionString in the Flat File Connection Manager to an expression. So that works fine and the text file's generated based on the expression.
Now, I need to email that file. Is it possible to access the ConnectionString property from another component?
I understand that I can use variables, but I don't want to write code for this.
Thanks.
If you want to use an expression in multiple components you have to store it in a variable.
Create an SSIS variable, change the variable Evaluate As Expression property to True and write the expression in the variable Expression property.
Then in each component just use this variable as Expression
Or just write the same expression in each component

Extract SubString from the File Name SSIS Expression

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.

SSIS derived column does not reflect variable's value

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.