简体   繁体   English

在 SSIS 中将 SQL 查询文件夹导出为 CSV

[英]Export a folder of SQL queries into CSV in SSIS

I am a newbie to SSIS and currently struggling with executing SQL task saving the result in a result set and exporting each table to a respective CSV using a data flow task.我是 SSIS 的新手,目前正在努力执行 SQL 任务,将结果保存在结果集中并使用数据流任务将每个表导出到相应的 CSV。

There are 15 .sql files stored in a folder which I am creating a variable called FolderPath pointing towards them.有 15 个.sql文件存储在一个文件夹中,我正在创建一个指向它们的名为FolderPath的变量。 Then I create a for each container that reads from a folder and create a variable in the variable mapping which is called SQLfile .然后我为从文件夹读取的每个容器创建一个,并在变量映射中创建一个变量,称为SQLfile

Inside the for-each container I have an execute SQL task which I changed its file connection variable and edited the expression to FolderPath + SQLfile .for-each容器中,我有一个执行 SQL 任务,我更改了它的文件连接变量并将表达式编辑为FolderPath + SQLfile

Executing this loop works, when the result set value is set to none.当结果集值设置为无时,执行此循环有效。 Now I am trying to connect the tables created from this loop in a data flow task.现在我正在尝试在数据流任务中连接从此循环创建的表。 I have no idea how to do this but I am guessing it has something to do with the result set.我不知道该怎么做,但我猜它与结果集有关。 When I change the result set to full result set my loop breaks.当我将结果集更改为完整结果集时,我的循环中断。 I am assuming you cant have a result set inside a loop.我假设你不能在循环中设置结果。

Now I am completely lost as I don't know how to save the result of those 15 tables and how to declare them as source in the data flow task.现在我完全迷失了,因为我不知道如何保存这 15 个表的结果以及如何在数据流任务中将它们声明为源。

Store the query in a variable.将查询存储在变量中。 Then use the OLE DB Source component in the Data Flow Task and set the 'data access mode' to sql command from variable .然后在数据流任务中使用OLE DB Source组件,并将“数据访问模式”设置为sql 命令 from variable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM