I want to take data from sql server database using for each loop and save into csv file and each time the number of columns are different so how can we achieve this in ssis.
i have tried in dataflow task but unable to find the solution.
I want to take data from sql server database using for each loop and save into csv file and each time the number of columns are different so how can we achieve this in ssis.
i have tried in dataflow task but unable to find the solution.
1条答案
按热度按时间b09cbbtk1#
For this you need to create a C# script task. In there you will have 2 files (listed below):
Then you need to have 2 variables you pass to the script task: This one is string type and contains the file name and path you want exported to like this C:\test.csv User::FileExportNameAndPath
This one will be an OBJECT type and contains the data set from your SQL query. You execute a SQL task and output results to OBJECT variable. User::ObjDataToSaveToExportFile
If you use the same variable names above you will not have to edit the script code below at all. You can even copy/paste the SSIS c# script task from one project to another and as long as you use the same variable names you wont have to edit anything
First one in Script Main: using System; using System.Data; using Microsoft.SqlServer.Dts.Runtime; using System.Windows.Forms; using System.IO; using System.Text; using System.Data.OleDb; // this is to convert he object from SSIS to a data table //using System.Text;
Send File named: ConvertToCSV.cs (though you can probably combine them into the main file.