Written by: Luis Miguel – Originally Published on: August 17, 2013
In my previous post I explained how to unzip a file using SSIS. The scenario presented unzipped a single CSV file and the file name was static, so if you executed the package more than once the CSV file would be overwritten.
In today’s post I’m going to present a method to rename the unzipped file so you can preserve the data when the package is executed multiple times.
Steps used to implement this solution
1 – Create a string variable to hold a daily timestamp
2 – Add an Execute SQL Task to populate the variable
Enter this T-SQL script to assign a value to the new_file variable
DECLARE @import_timestamp CHAR(8)
DECLARE @new_file VARCHAR(64)
SET @import_timestamp = CONVERT(VARCHAR, GETDATE(), 112)
SET @new_file = ‘c:\unzip\sale_orders_’ + @import_timestamp + ‘.csv’
Enter this C Sharp code to rename the file
public void Main()
old_file = “c:\\unzip\\sale_orders.csv”;
new_file = Dts.Variables["User::new_name"].Value.ToString();