SSIS 2008 lookup - ssis

I use a lookup component. When No Match output, I insert the rows into a target table. I would like to update the target table with this rows when Lookup is matched.
How can I do that?
Thx!!

In the Lookup transformation, map Lookup Match Output to an OLE DB Command transformation. In the OLE DB command transformation use an UPDATE statement or a stored procedure and map the columns accordingly. Here is a link that describes how to use OLE DB Command transformation.
Please note that if you have too many rows to update, OLE DB Command transformation might slow down things.
There are couple of options:
You can use a second Lookup Transformation between the first Lookup transformation and the OLE DB Command. In the second lookup, map all the columns between source and destination that you will be updating including the key column and redirect the output to OLE DB Command only if there is not matching records.
Split the output from Lookup Match Output to multiple outputs using a sequence number and have multiple OLD DB Command transformations. Please find my answer in this Stack Overflow question where I split output from one transformation into multiple output before redirecting to an OLE DB Command.
Hope that helps.

Related

Package is struck at "Execute phase is beginning" at Lookup task

I have used a Lookup in my data flow task. When I use Full Cache mode, the data flow task runs fine. But when I use Partial Cache or no Cache in my lookup, the records do not go past the lookup task and it keeps running for hours. I have checked for errors but there aren't any errors displayed. Could anyone please help me on this?
A Lookup is not appropriate for your task. Instead:
Add an OLE DB Source to pull in the data
Sort the records from the incoming source and the OLE DB Source
Perform a merge join (Full outer).
Add a Derived Column Transformation to check for ISNULL on the two joining columns. Create a new output column Called Action. For the NULLs in the target then you will tag that as an INSERT record.
Add a conditional split to send the INSERT record to an OLE DB Destination to insert the new records.
You can also check to see if there are matches between the two populations and perform updates, or look for NULLs in the source and DELETE in the destination.

SSIS sql command two '?' mapping one parameter

I am in the middle of SSIS sync two tables.
The problem happens while updating with mapping.
I separated inserting data and updating data. It is supposed to be conditional updating. Only update the rows which are different from the source table.
I added OLE DB Command and wrote sql.
UPDATE LocationSearch.dbo.AMENITY
SET
[AMENITY_TYPE]=?
,[AMENITY_NAME]=?
,[FITNET_AMENITY_NAME]=?
,[EXCLUDE_MIGRATION_FROM_FITNET_TO_PLPORTAL]=?
WHERE ([AMENITY_ID]=?) and (([AMENITY_TYPE]!=?) or ([AMENITY_NAME]!=?) or ([FITNET_AMENITY_NAME]!=?) or ([EXCLUDE_MIGRATION_FROM_FITNET_TO_PLPORTAL]!=?))
some of the question marks are the same parameters. Therefore causes the mapping problem for one parameter cannot map two column names.
Is there any sql command to avoid this mapping issue or other solutions?
Thank you
Try this using stored procedure executed with OLE DB Command.
So you can assign just the parameters you need (are available), but inside the SP use the parameters as much times you have to.
BR

Getting the second dataset from an OLE DB Source in SSIS

I need to read data from a DB1 and write them to another DB2.
I use a complex query with CTEs and temp tables and no, i can't put this query in a SProc.
I use an OLE DB source and an OLE DB Destination.
When i put the query as SQL Command in the OLEDBSource I get the usual complaint about not being able to determine metadata because a CTE is using a temp table.
I can't use the "with result sets" workaround because it is not a SProc. So i try with the other workaround, the "SET FMTONLY ON/OFF" .
Now the OLE DB Source accepts my query but it outputs two datasets, the first empty and the second is the data I need. The OLE DB Destination doesn't write a single row because it is reading only the first resultset, the empty one.
How can i solve this?
I cannot change the temp tables in something else and basically i can't change the query. I am looking for a SSIS solution if possible, not a SQL solution.
Thx.
For an SSIS solution, you cannot use an OLE DB Source. That component can only access the first result set.
What you can do is use a Script Transformation as your data source, and access the second result set in the usual way, and send its columns to the output of the script.

How to insert/update rows from MySQL to SQL Server by using SSIS

I'm looking for the best practice to insert or update rows from a MySQL connection to a SQL Server connection.
First of all, I added a ADO.NET data source to grab MySQL content (a simple table Supplier with two fields id and name). Then, I added a Lookup transformation to split new rows / updated rows. It works well when I need to insert new rows. However, I would like to use a Command OLE DB to update existing rows but It doesn't work due to a incompatibility between my connection manager and the component (ADO.NET vs OLE DB).
Any idea to update modified rows ?! Should I use a cache component ?!
Thanks in advance !
Just get rid of the lookup and conditional split all together.
Outside of your SSIS package, build a staging table that contains the fields you need for inserts/updates.
In your SSIS Package, create a control flow that does the following:
Execute SQL Task to truncate the staging table.
Data Flow task to load the MySQL data from the source system to the staging table. If you can do this based on a "changes-only" type process, such as using a timestamp that you check, it would be faster.
Execute SQL Task to perform an UPDATE statement on your target table using the staging table joined to the target table.
Execute SQL Task to perform an INSERT statement on your target table using a query based on the target table and your staging table (with a WHERE NOT EXISTS or some such on a key fied)
I would change the SQL connection to use OLE DB. As well as allowing the OLE DB Command to work, you may also find the OLE DB Destination is faster.

Which SSIS transformation can perform 'NOT IN' constraint used in SQL query?

I have two OLEDB Data Sources that have similar columns:
TMP_CRUZTRANS
-------------
CUENTA_CTE numeric (20,0)
TMP_CTACTE_S_USD
----------------
CON_OPE numeric(20,0)
I need to substract all the similar values between this two tables and keep the rows which are different. Is there a transformation/task within SSIS that can perform NOT IN constraint normally used in SQL query?
Currently, I am performing this operation using Execute SQL Task on Control Flow.
The top Data Flow creates the first table TMP_CRUZTRANS (Merge join between other 2 tables... But I guess that's not important for my question) that i need to keep the different values with the second table.
In the Execute SQL Task, I have the following statement:
INSERT INTO [dbo].[TMP_CYA]
SELECT RUT_CLIE, CUENTA_CTE, MONTO_TRANSAC
FROM [dbo].[TMP_CRUZTRANS]
WHERE CUENTA_CTE NOT IN (SELECT CON_OPE FROM TMP_CTACTE_S_USD)
Finally, with the new table TMP_CYA I can continue with my work.
The problem with this approach is that the TMP_CRUZTRANS got like 5 millions of rows, so it's VERY slow inserting all this data into a table using Execute SQL Task. It takes about like 5 hours to perform this operation. That's why I need to do this inside the Data Flow task.
You can use Lookup transformation available within Data Flow task to achieve your requirement.
Here is a sample that illustrates what you are trying to achieve.
Create a package with data flow task. Inside the data flow task, use OLE DB Source to read data from your source table TMP_CRUZTRANS. Use Lookup transformation to validate the existence of the values against the table dbo.TMP_CTACTE_S_USD between given columns. Then redirect the non-matching output to OLE DB Destination to insert rows into table dbo.TMP_CYA
Here is how data flow task would look like in place of the Execute SQL Task that you are currently using.
Configure the Lookup transformation as shown below:
On the General tab page, select Redirect rows to no match output from Specify how to handle rows with no matching entries because you are interested only in non matching rows.
On the Connection tab page, select the appropriate OLE DB Connection manager and select the table dbo.TMP_CTACTE_S_USD. That is the table against which you would like to validate the data.
On the Columns tab page, drag the column CUENTA_CTE and drop it on CON_OPE to establish the mapping between source and lookup tables. Click OK.
When you connect the Lookup transformation with OLE DB Destination, Input Output Selection dialog will appear. Please make sure to select Lookup No Match Output.
Here is the sample before executing the package.
You can see that only 2 rows non matching rows have been transferred to OLE DB destination.
You can notice that the destination table now contains the two non matching rows after package execution.
Hope that helps.