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.