I've got a ssis package that does a simple enough data import from a text file into a database table. The import file name needs to be configured as a dynamic source since the file name will change. So my file name will have following pattern: bookNames_Shopping_05_02_2016.txt --> bookNames_Shopping_ will be constant but the date stamp will change.
I set up a variable called filename, and in the connection manager's properties window, I set the ConnectionString property to @[User::filename]. How do I set the filename variable to read the file name that is in the folder that the connection manager is pointed to? P.S. I know it can be done inside a For Each loop but since I don't have multiple files but a single file that needs to be processed, I **don'**t want to use the for each loop.
Full path for the file: \XYZYUC3312B6\SHARE\Bound\bookNames_Shopping_05_02_2016.txt
An alternative to applying a loop is using an expression. Assuming the single text file being read contains in its name the same date in which the SSIS package will process it, you can do the following:
`"\XYZYUC3312B6\SHARE\Bound\" + @[User::FileName] + "_" +
RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2) + "_" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2) + "_" + (DT_STR, 4, 1252) DATEPART("yy" , GETDATE()) + ".txt"
Select the Evaluate Expression button in the lower left. If this works, it should display your full file path including a concatenation of the current date.
\XYZYUC3312B6\SHARE\Bound\bookNames_Shopping_05_04_2016.txt
Select OK button and you're all set. I ran this in BIDS under SQL Server 2008R2. If you're using SQL Server 2012, then in Visual Studio 2010, you can set up the same expression directly for the FileName variable instead.
From this point, just apply the bookNames_Shopping connection string in our dataflow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With