ssis中动态表创建和加载数据 [英] Dynamic table create and load data in ssis

查看:27
本文介绍了ssis中动态表创建和加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对ssis有一点疑问,文本文件有基于位置的位置数据需要在sql server中动态创建表并使用ssis包加载相关的位置数据,源文本文件具有如下示例数据

I have small doubt in ssis, text file have location data based on location need to create table dynamicaly in sql server and load related location data using ssis package, source text file have sample data like below

id |姓名 |地点1 |abc |海德2 |巴努|陈3 |jai |bang4 |哈里|海德5 |纳尼 |海德6 |班蒂|砰7 |kali |chen

id | name | location 1 | abc |Hyd 2 | banu |chen 3 | jai |bang 4 | hari |Hyd 5 |nani |Hyd 6 | banti |bang 7 |kali |chen

基于这个文本文件加载,我们需要动态创建位置表并加载相关数据.因为有些时候文本文件中可能有更多的位置,这种情况我们需要动态创建表并加载它.请告诉我如何实现此任务使用 ssis.我们需要 foreach 循环容器,但不知道如何实现.请告诉我解决此问题

based on this text file load we need to create location tables dynamically and load related data.because of some time may have more location in text file that situation we need to create table dynamically and load it.please tell me how to achive this task using ssis.we need foreach loop container but don't how to achive this.please tell me to solve this issue

推荐答案

1) DFT 任务(获取不同的位置和相应的表名)

1) DFT task (Get distinct locations and respective table names)

  • 创建第一个 DFT 以从文件中获取不同的位置.添加聚合转换并将输入列作为位置并选择操作作为 GroupBy 这将为您提供文件中的不同位置
  • 然后,添加派生转换以获取位置及其各自的表名表名 - (DT_STR,50,1252)("dbo.LocationList" + location)位置 - (DT_STR,50,1252) 位置
  • 添加记录集目标并将 TableName 和 Location 值存储在类型对象的变量(名称 = 位置)中

2) Foreach 循环容器任务(创建表并存储数据)

2) Foreach loop container task(Create tables and store data)

  1. Foreach 循环容器配置 -

  1. Foreach loop container configuration -

  • 选择枚举器为Foreach ADO 枚举器"
  • 选择源变量作为位置"
  • 枚举器模式 - 第一个表中的行
  • 在变量映射中,分别在两个变量location"和Locationtable"中获取位置和相应的表名.

在容器中添加 SQL 任务(如果表不存在则创建表)

Add SQL Task in container (to create table if it is not present)

  • 将 SQL 源表达式提供为 -

"如果 Object_Id('" + @[User::Locationtable] + "') 为 NULL创建表" + @[用户::位置表] + "(身份证号码,名称 Varchar(50))"

在容器中添加 DFT 任务(将数据导入到相应的表中)

Add DFT task in container (to import data into respective tables)

  • 添加平面文件源以从同一源文件中获取加载数据
  • 添加条件拆分并添加表达式location == @[User::location]"以获得匹配的输出
  • 添加 OLEDB 目标并将访问模式设置为OpenRowset Using FastLoad From Variable"
  • 选择变量用户::位置表"

注意 - 您需要为User::Locationtable"变量提供默认值,其表名存在于数据库中并具有相同的架构,以便您可以在第二个 DFT 任务中映射列.

Note - you will need to provide default value to "User::Locationtable" variable with table name which is present on database and has same schema, so that you can map the columns in second DFT task.

这篇关于ssis中动态表创建和加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆