Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 General SSIS package to export any table into .csv

Author  Topic 

sql_er
Constraint Violating Yak Guru

267 Posts

Posted - 2013-03-18 : 14:32:22
Hi guys,

I need to create an SSIS package that takes a table name as a parameter and exports out its data in a CSV file.

The challenge is that if I use a data flow task and a flat file connection manager (for csv export), I have to specify the file/table structure. I will not know the table structure until the run time because it is input specific.

Has anyone had a similar problem and implemented a solution?

I was thinking along the lines of using C# in a script task, but could not come up with a full blown solution.

Any advise is appreciated.

Thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-18 : 14:37:51
does the table structure vary at runtime? then only way is to create object of data flow task programatically inside script task.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sql_er
Constraint Violating Yak Guru

267 Posts

Posted - 2013-03-18 : 14:44:50
Yes, input tables can be of any structure, so they will vary from run to run.

When you say "create object of data flow task programatically inside script task" are you referring to SSIS API?

Thank you!
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2013-03-18 : 21:08:37
create destination table programatically by reading csv file and dynamically creating a table that matches the csv file.

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-19 : 01:11:48
quote:
Originally posted by sql_er

Yes, input tables can be of any structure, so they will vary from run to run.

When you say "create object of data flow task programatically inside script task" are you referring to SSIS API?

Thank you!



Something like this

http://www.selectsifiso.net/?p=288

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sql_er
Constraint Violating Yak Guru

267 Posts

Posted - 2013-03-19 : 09:19:13
Thanks guys. Using SSIS API seems quite involved for seemingly simple task.

I'll be looking into using bcp as a starting point.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-19 : 11:39:13
hmm..that would be much better. you can put logic to generate column headers also dynamically in bcp

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -