Dynamic table create and load data in ssis

安稳与你 提交于 2019-12-01 14:44:07

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

  • Create first DFT to get distinct locations from file. Add aggregate transform and give input column as Location and select oparation as GroupBy which will provide you distinct locations in file
  • Then, add derived transformation to get the locations and its respective table name TableName - (DT_STR,50,1252)("dbo.LocationList" + location) Location - (DT_STR,50,1252)location
  • Add recordset destination and store the TableName and Location values in variable (name = Locations) of type object

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

  1. Foreach loop container configuration -

    • Select enumerator as "Foreach ADO Enumerator"
    • select source variable as "Locations"
    • Enumerator mode - Rows in first table
    • In variable mappings get location and respective table name in two variables "location" and "Locationtable" respectively.
  2. Add SQL Task in container (to create table if it is not present)

    • Provide SQL source expression as -

    "If Object_Id('" + @[User::Locationtable] + "') IS NULL CREATE TABLE " + @[User::Locationtable] + " ( id int, Name Varchar(50) )"

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

    • Add flat file source to get load data from same source file
    • Add conditional split and add expression "location == @[User::location]" to get matching output
    • Add OLEDB destination and set access mode as "OpenRowset Using FastLoad From Variable"
    • Select variable "User::Locationtable"

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!