Posted: 12/15/2011
Hello All,
I have an simple ssis package that extracts the data from the file from specified location and load into a table. Right now it is working fine. Rightnow it takes the file from current date. I want to change the file name dynamic and execute the package dynamically. I mean if I want to execute dec 1st file it should execute and if I want to execute dec 3rd file it should execute. Its more like a stored procedure with a parameter as a file name. Is there any way to do this in ssis.
Please assist.
Thanks
The company that sponsors BIDN, Pragmatic Works has a "cheat sheet" of variable expressions for SSIS here ( it's a free chart / download ):
http://pragmaticworks.com/cheatsheet/
And the first one is adding today's date to a filename - sounds like it might be exactly what you're after.
A few things to remember when you create a variable with an expression:
When you create it, make sure to go to the properties and set "Evaluate as expression" to true.
Keep in mind that when the package loads, a value will get set, but SSIS does not automatically update the value of the expression, so when you change something, click "Evaluate Expression" to manually update the value and make sure it's generating what you're after.
You cannot "set" a value in your variable window if your variable has an expression and is evaluated as an expression - whatever you "set" will get overwritten when the package is executed.
Hope it helps,
Keith Hyer
Posted: 12/16/2011
Thanks keith for your reply. I have already defined a variable for my package to pull today's file and it is working fine.
I have a working package that will take the file and loads into a table everyday. I have defined a variable for the file path and used that variable in my connection string property of flat file connection manager. I have given the expresison for the variable as
"c:\\Data_Mart_Account_" + (DT_WSTR,4)(YEAR(GETDATE())) + "-" +Right("0" + (DT_STR,4,1252) DatePart("m",getdate()),2) + "-"+RIGHT("0" + (DT_STR,4,1252) (DatePart("d",getdate())),2) + ".csv"
So the package will take the current date's file and load into a table. But now my requirement is I want to have this file path as dynamic. I mean my current file path will take the file "data_mart_account_2011-12-16.csv" from c folder and load into a table. What I need to do for the package if I want to load "data_mart_Account_2011_12_01.csv" (dec 1st file)" or if I want to load "data_mart_Account_2011-12-05"(dec 5th file). I can change my variable for dec 1st and dec 5th and get the file for dec 1st and dec 5th. But I dont want to do that everytime . Is there any way that I can do like just push a button and package will execute whatever file we want to load into a table.
Thanks for your time.
Posted: 12/18/2011
Ok, I think I'm following now.
You have 2 options that I can think of off hand ( there are probably more ):
Option 1:
You could set up a parameter on the package with a default value ( in your date format ) of "{0000}{00}{00}" ( 8 zeros ) - then use a derived column does an "inline if". The expression for that in your derived column would look something like this:
condition ? true : false
( ParamName = "00000000" ) ? "c:\\Data_Mart_Account_" + (DT_WSTR,4)(YEAR(GETDATE())) + "-" +Right("0" + (DT_STR,4,1252) DatePart("m",getdate()),2) + "-"+RIGHT("0" + (DT_STR,4,1252) (DatePart("d",getdate())),2) + ".csv" : "C:\\Data_Mart_Account_" + (DT_STR,8,1252)( ParamName )
Where "ParamName above is your input parameter name. Then you'd just modify the job parameter if you needed to override it to run your job.
Option 2:
Same concept, just use a table to drive it. If you have a value in your table that is not "00000000" then use it. Otherwise, calculate as normal.
Hope that helps or gives you an idea! If it's not clear, let me know and I'll work up an example with more detail.