SSIS: Read property from another component? - ssis

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

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.

How to pass variables as parameters to subreports using SSRS

I am working on an SSRS project which has main report and sub reports. To the subreport, I would like to pass a variable that uses stuff sql syntax. This variable will have comma separated values. I would like to know how to pass variables as parameters to subreports.
If you go to the Action tab in the properties window, there is an area at the bottom which you can assign the parameters to be passed to the next report. If you want to pass an existing parameter, you would send
=Parameters!MyParameterName.Value
as the value.
I'm not sure what "stuff sql syntax" means, but you can pretty much put whatever you want into the value field as a string and parse it in the next report.

ssis expression file path

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

SSIS connection string based on a variable

This is a follow up to my question: SSIS connection parameter based on parameter/variable
I now can see how to construct a variable from other variables, but it does not appear possible to then use that variable as the ConnectionString for the Connection. That appears to only allow variables.
How can I use my newly concatenated variable as the ConnectionString?
Ok, I can answer my own question now. It is a different location than if you want to use a parameter to set the ConnectionString.
Click on the Connection in Connect Manager and in the Properties window, expand Expressions. There you can click the ... to set it to a variable.

SSIS multiline string variables , in VS 2008

I need to store a large query into a string variable.
When I paste the sql query into the Value property of the variable, I see only one line.
I am using VS 2008 , BIDS to design the package.
I think this is a bug as stated here,
what I am actualy intersted is a workaround to bypass this.
We use a parameters table in a SQL database, then load long strings into variables using a simple SQL query. This has the additional advantage that you can refactor the query code without opening SSIS.
It also allows multiple packages to easily share common query code.
Edit: Of course, if you only want to do this once...
Manually edit the XML. Put a placeholder value in the variable, then open the .dtsx in a text editor, locate the placeholder value, and replace it with the value you need.
Please back up your package prior to doing this.
Another work around - you can set the EvaluateAsExpression to True and put the SQL query in the Expression. The Expression will have a ... button which you can click to edit a multi-line value.