I have a Master table which has SourceName(Ex:- CSV File Name) and DestinationName(Ex:- Sql Table Name) as I know the source and destination; do we have any approach in SSIS to load files from source to destination dynamically. I don't want to create 50-60 data loads in SSIS Do we have any other better approach?
My Table looks something like this
Source Destination
File1.csv dbo.Table1
File2.csv dbo.Table2
File3.csv dbo.Table3
Note:- Schemas may differ for each files
Please suggest a best approach which saves a lot of effort
My apologies I misread the question originally I thought you wanted to dynamically EXPORT data from tables. I was starting to work on a solution to do this myself a while back but never completed it. I am leaving the below here in case you or anyone else comes here and wants a way to dynamically EXPORT data to csv files.
This is the code from my C# script task that will take a dataset you populate from a SQL task and output to an object data type. You can pass this any data set you want and it will dynamically create a .csv file for you. NOTE: You have to be careful on very large data sets because it can use up memory.
I have 2 files (though you can combine them into one if you want:
This works by passing it 2 variables in the SSIS ReadOnlyVariables: User::FileExportNameAndPath,User::ObjDataToSaveToExportFile
FileExportNameAndPath - Is the full path you want to export the file to with the file name/extension. You can use Expression Builder and other variables to create this to be whatever you want in a loop (grab your table name into a variable and parse a date to add that to your file name if you want).
ObjDataToSaveToExportFile is an object variable that you populate in previous step with Execte SQL task (whatever query and data you want to generate in your .csv file). On this step you have to have the output be variable, full resultset, and have the variable be: ObjDataToSaveToExportFile
If you use these same variable names you can just copy/paste this C# Script task across different packages without having to edit the script task at all.
This is code in file: ScriptMain.cs
I have a second file in my project named: ConvertToCSV.cs and the code in there is:
For the expression bulder for the FileNameAndPath You can use this in your variable and update the path/name as you wish and it will generate a path like this:
Here is image of the SQL Task with how you have to set it up for full result set:
Then on the Result Set Tab it should look like this: