Using dynamic SQL in an OLE DB source in SSIS 2012

前端 未结 2 1786
天命终不由人
天命终不由人 2021-01-13 08:50

I have a stored proc as the SQL command text, which is getting passed a parameter that contains a table name. The proc then returns data from that table. I cannot call the t

2条回答
  •  孤街浪徒
    2021-01-13 09:38

    So I ask out of kindness, by why on God's green earth are you using an SSIS Data Flow task to handle dynamic source data like this?

    The reason you're running into trouble is because you're perverting every purpose of an SSIS Data flow task:

    • to extract a known source with known metadata that can be statically typed and cached in design-time
    • to run through a known process with straightforward (and ideally asynchronous) transformations
    • to take that transformed data and load it into a known destination also with known metadata

    It's fine to have parameterized data sources that bring back different data. But to have them bring back entirely different metadata each time with no congruity between the different sets is, frankly, ridiculous, and I'm not entirely sure I want to know how you handled all your column metadata in the working 2008 package.

    This is why it wants you add a WITH RESULTS SET to the SSIS query - so it can generate some metadata. It doesn't do this at runtime - it can't! It has to have a known set of columns (because it aliases them all into compiled variables anyway) to work with. It expects the same columns every time it runs that Data Flow Task - the exact same columns, down to the names, the types, and the constraints.

    Which leads to one (terrible, terrible) solution - just stick all the data into a temporary table with Column1, Column2 ... ColumnN and then use the same variable you're using as the table name parameter to conditionally branch your code and do whatever you want with the columns.

    Another more sane solution would be to create a data flow task for each of your source tables, and use your parameter in a precedence constraint to just pick which data flow task should run.

    For a solution this poorly tailored for an out-of-the-box ETL, you should also highly consider just rolling your own in C# or a script task instead of the Data Flow Task provided by SSIS.

    In short, please don't do this. Think of the children (packages)!

提交回复
热议问题