Google search bar

March 07, 2012

Providing Metadata to SSIS dataflows

Recently I've begun to work with SQL Server Integration Services (SSIS) to extract data and load it into a data warehouse.  I discovered a seemingly absurd statement in an existing package.
IF 1=2 SELECT CAST(NULL AS...), CAST(NULL AS ...) ...
This was the very first statement in a long complicated SQL script that eventually...way down at the end of the file...after hundreds of lines...selected a result set that would be used in a SSIS dataflow.

Oh, this must be nonsense, I thought. Let me ask if I can take this out.  There is no reason to have an if that tests a contradiction (the opposite of tautology is, which is what we have here).


Well there is a good reason why the contradiction had to be there and I couldn't remove it.

SSIS must determine what columns are coming into it.  It does this by looking at the first select in the SQL script and assuming that the columns and datatypes it sees there are what will flow into it.  So, in this very complicated script, the IF 1=2 statement must be there.

If the sql script were simply a single select statement, the fake first select wouldn't be necessary since SSIS could get its result set metadata from the one-and-only select statement.

No comments: