SSIS:根据Excel文件名,将多个格式相同但文件名不同的Excel文件插入多个数据库表目的地

我一直在研究这一段时间,没有发现任何明确的。 我有多个Excel文件,其中包含不同项目的结算信息。 我们可以把它们看作是项目A的文件A,项目B的文件B和项目C的文件C.它们从Outlook,按规则移动到一个公共文件夹。

我想使用SSIS来确定目标位置的文件名。 在上面我们非常简单的例子中,我想循环浏览文件夹,并将文件A读到表A,文件B到表B和文件C到表C.所有表都包含在一个SQL Server数据库中。 一旦完成,我想文件被移动到设定的目的地(文件夹A,文件夹B和文件夹C)

我假设你将不得不添加一个脚本组件来获取文件名variables,parsing它来恢复A,B,C,并使用它来指示某种types的IF语句来定位相关的目标位置。

唯一的其他小复杂的是,我想检查每个表,以确保我没有添加任何重复的数据 – 假设我会在每个表目的地之前使用查找组件…

我可以find每个循环容器的信息,并dynamic设置源位置,但不是基于文件名称的dynamic目标。

这在SSIS中看起来像是一个合理的事情吗?是否有人能够帮助我,或者可能指向我还没有发现的来源?

任何帮助将非常感激 – 请让我知道,如果你想进一步的细节。

谢谢

正如在注释中所读到的,只要它们共享不同的表结构,我们就不能在for-each循环中加载到多个表中。

如果所有的Excel表格都具有相同的结构,我们可以避免这种复杂性。 以下步骤可能会对您有所帮助。

1. DFT 1 a. Develop an SSIS package with a DFT to load all your excel files into a single stage table. b. In the table in addition to the excel columns, add a separate column to store file name. c. Use a for-each loop with 'Foreach ADO.NET Schema Rowset Enumerator'. d. Again it will be help you if excel files share a common file name pattern.(ProjA_140527.xls, ProjA_140528.xls,ProjB_140527.xls etc), so that you can use Proj*.xls to fetch the excel files. 2. DFT 2 a. After this DFT, add another DFT. use an OLE DB Source taking data from stage table. b. After the source, add a conditional split. Write expressions based on excel file name column. c. if you have 5 projects, conditional split will have 5 outputs and 1 non-matching output. d. Map each project tables to conditional split outputs.