Showing posts with label destination. Show all posts
Showing posts with label destination. Show all posts

Wednesday, March 21, 2012

How can I append only new rows in a table using SSIS?

Hi,

Im creatting an SSIS project that uses an Data Flow OLE DB Source to read data from an SQL Table and import it into a Destination table using Data Flow OLE DB Destination. but now everytime I run the project it appends all the rows not the new data rows only. How can I make the application so that it appends only the new data from a source table to a destination table. Is there maybe another Data Flow Control that can copy source table to destination and the next time it runs it only copy new rows. or any other way to do this using SSIS.

Your assistance will be highly appreciated.

Use the Lookup component. Set it up to return the keys of the destination table. Map the keys to your input data. Then grab the red arrow coming out of the lookup and hook it up to your destination.|||

Hi Phil,

Im new to SSIS, please bear with me. I have maped the lookup component to the destination table and hook the redline out of the lookup to destination OLE DB Destination which is also mapped to a destination table. It coppies all the rows.

Please email me the sample project, my email is sibu.khanyile@.enerserv.co.za

Thank you in advance

|||Make sure that you use a derived column to TRIM() the key fields going into the lookup component. Also know that the keys must have the same CaSE as those in the destination table in order to match.

Monday, March 19, 2012

How can Data Flow destination be a temp table?

I have a series of data flow tasks that I want to output to a temp table. I've set the data source for RetainSameConnection and the Data Flows are DelayValidation. The OLE DB data source inside the Data Flow works fine, but the data destinations don't offer a # or ## as a target. I've tried every destination that sounds logical, without success.

Any pointers? ... Thanks!

I do not get # tables, but that is because the UI cannot be the same connection that created them, so makes sense. Entering the table by hand, using the property grid directly would probably still work for # tables. ## tables get listed in the UI though as expected

Have you selected a connection pointing at your tempdb?

|||

Hi Darren - thanks for responding.

I do use the same connection, and it does persist. I can select from the #temp or ##temp table using a SQL Task.

First, I create either a local temp table (let's call it #temp_local) or global (##temp_global) using an Exec SQL Command. The next task is a Data Flow, with a Source OLE DB being a SQL Query from a different connection than the temp table, and the OLE DB Destination is supposed to be the #temp_table or ##temp_table I just created. However, the dialog box for selecting the tables does NOT include ANY temp tables.

|||Run a profiler trace, and verify the call to list the tables, and check things like the DatabaseID, is it tempdb? It sounds like you have tripped up somewhere. Wrong server? Wrong database? As I explained above I cannot reporduce this behaviour.|||

Looks like I found the answer, thanks to MCS consultant Brian Jackson. Check out http://msdn2.microsoft.com/en-us/library/bb332055.aspx for information on metadata. Evidently GetTableData inconsistently returns temp table meta data, whether it's a global or temp table.

I did find that you can enter the ##temp table name directly into the property box, but not by using the Edit box. And doing that works, kind of, after faking out the column matching dialog on the destination Editor by running it in-stream in debug, after pausing for a breakpoint. That way, the data flow sees the temp table. And the DelayValidation setting retains the pattern matching.

Even so, you're better off building an Expression query and using in-memory transforms, because the inconsistent return of meta data means you end up with data flows that fail for no apparent reason, or consistent error message. Debugging was driving me mad! :-)

Another case of "it's better to re-write, than to reuse" your code sometimes.