Data Flow Task inside ForEach - how to change column mappings on the fly?

  • Hi all,

    I am learning SSIS and my first task is to put together a package which can import a number of tables from one database into another. The idea is that the target database has a table with a list of tables to import from the source DB.

    I've got a Data Flow Task inside a ForEach loop, and that side of things appears to be setup correctly. However, when the loop gets to the second table to import, it fails because the column mappings are different for table 2 as from table 1. When I first created the Data Flow Task, I set it up using table 1 as my source and as such, it contains the column mappings from table 1.

    So, before I attempt to import table 2, I need to somehow dynamically set the column mappings to match table 2. The good news is that I am not attempting to perform any transformations, purely copy the table from one DB to another.

    Does anyone know how I can achieve this? I am thinking I may need to query syscolumns to get the columns (perhaps as below) and loop through them, but as to how to actually do this, I am stumped.

    /******/

    select

    sc.*

    from syscolumns sc, sysobjects so

    where

    so.id = sc.id

    and

    so.name = @MyTableName

    order by sc.colid

    /******/

    Thanks in advance,

    Matt.

  • Hmmm... seems you can't. It is not possible to alter the package that is running. Instead, you need to alter a package that is NOT running, via a script task, then execute that using an Execute Package task.

    I'll try that and get back to you.

    Matt.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply