First off, my appologies, I am a newbie to programming and SQL.
I have an SSIS package that inserts rows to a database. On occasion I get a constraint error on one of my reference tables. So far it is because of missing data.
What I want to do:
I want to redirect the row, grab the data and insert it into the reference table then reprocess the row.
A) is this possible? I have looked at doing a lookup task prior to the row being inserted to the database. I have also looked at using a sql task in my error handling, but having issues with the code (see B).
B) I need help with the code. How do I pull the information from that single row then insert it into the database? Do I use a variable? Is this a select statement?
Any help would be greatly appreciated.
There is more than one way to solve this. Here are three:
1) (Pure SSIS)
Use a lookup task to check for existence. When matched then continue as currently. When not matched:
a) Insert a suitable row into the reference table using a OLEDB command
b) Insert to child table as usual.
Use a lookup as above. When matched, all OK. When not matched
a) Direct to a staging table
b) At the end of the dataflow, run a stored proc to process and insert the rows in the reference and staging tables as required.
3) (Use SSIS as little as possible)
Use the solution suggested by Mansfield.
I would expect (2) to be the fastest, (1) is the most elegant and (3) is probably easiest to set up, maintain and troubleshoot - for SQL folks anyway. In my opinion, of course.
One problem with (1) is that you cannot use a cached lookup - so performance is likely to be average at best.
Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this
If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.
Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.