Question

I have a flat file data source I would like to load into a sql server table. One of the columns in the table however should be sourced from the result of a database query. The query is entirely independent of the flat file data so I'm not sure a join is appropriate here. Rather than use a trigger-based solution I'd like to solve this in ssis if practical.

The query returns one value which would be used for every row from the flat file. It would be good if the query were not evaluated once per row obviously.

Was it helpful?

Solution

If the query just returns one value, you can:

  1. Run a Execute SQL Task with your query, saving the result into a SSIS package variable.
  2. In the data flow task, read in the flat file, then add a Derived Column transformation, where the expression is simply your package variable.
  3. The data flow can now be directed into your table of choice, including this value.

You can also:

  1. Load the data first, leaving this field null.
  2. Execute a set-based UPDATE statement to update all records on the target table.

This, of course, assumes that your target table is empty.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top