SSIS Condition that include two connections/data bases

ssisssis-2012

In a SSIS package , I need some sort of condition that include two connections.

The simplified problem is:
A simple CSV import to SQL Server, DB1, table 1( col1, col2 ).
I need to populate table 1 > col2 = '1' if col1 is found in another database , DB2 > table 2 ; db2 is specified as a different connection in package.

and table 1 > col2 = '2' if col1 is not found in the lookup database.

any guidance is appreciated,
ta

Best Answer

Put the CSV import in one data flow, then in a dependent data flow use an OLE DB Source that contains the results you need as the output of a SQL query. Feed that into an OLEDB destination.

Your query would look similar to:

SELECT t1.col1, 
CASE WHEN EXISTS (SELECT null FROM db2.dbo.table2 t2 WHERE t2.col1 = t1.col1) THEN '2'
ELSE '1' END as [col2]
FROM db1.dbo.table1 t1