luka032
luka032

Reputation: 955

Insert into Table if ID doesn't exist, otherwise skip

I am using Kettle Pentaho data integration. I need to skip inserting IdN column from first table (first db) if it already exists int second table (second db).

In my kettle's design I've got Table Input (which returned me some rows).

I've need to select distinct IdN column from that returned rows, and to insert them (all distinct ids) into second table of second database (so I avoid duplicating ids).

I've tried with this code in execute sql statements :

INSERT INTO {SecondTable}
SELECT DISTINCT (IdN) 

But returned with error:

Invalid column name 'IdN'.

And what confuses me, is that I have checked parameter IdN into "Field name to be used as argument" under "Execute SQL section" node of my kettle's design, which is valid column name I've got returned from previous table input node.

Upvotes: 1

Views: 902

Answers (2)

luka032
luka032

Reputation: 955

I've succeeded using "Unique rows" step in Kettle, it will do exactly what I wanted, just specify columns on which to check value existence.

Upvotes: 1

Jeremy Shankling
Jeremy Shankling

Reputation: 26

To be sure I am understanding. You are trying to write a query to select the idN column from one database into a table in another database. If so the query should look like this

    Insert into db1.dbo.tableName1(colname)
    Select Distinct colname From db2.dbo.tablename2

Upvotes: 0

Related Questions