Page 1 of 1

How to handle serach and insert a table at the same time?

Posted: Tue Sep 21, 2004 1:53 pm
by olgc
Hi there,

A job needs to insert a record into a table. before inserting, the table is searched to see if the record is already in the table. If it is, brings back its primary key. The Database is DB2 7.2.9. When the job is run, it hangs up. How can the transaction be set to allow the search and insert a table at the same time?

Thanks every body,

Posted: Tue Sep 21, 2004 1:56 pm
by chulett
How are you actually doing this "search"?

Posted: Tue Sep 21, 2004 2:08 pm
by olgc
The code is

SELECT * FROM IDBA.PLAYER WHERE PLAYER.FIRSTNAME=? AND PLAYER.LASTNAME=? AND PLAYER.POSTALCODE=?

Posted: Tue Sep 21, 2004 2:14 pm
by ketfos
Hi,
You can have a lookup which does a lookup for the existing key.
In the tranfromer you can have two outputs.
1. Insert Record (constraint on transformer ISNull(key)
2. Update Record (constraint on tranformer Not(ISNull(key))

Ketfos

Posted: Tue Sep 21, 2004 2:23 pm
by chulett
Best Practice would have you create, in a "preprocessing" step or job, a hash file with all of the current business keys and their corresponding surrogate keys. Ideally, you would constrain that build to whatever records are currently staged for processing. Then your lookup can be done against the hash file and a decision made based on the success or failure of that lookup. As noted, you could also split out seperate links for your Update and your Insert actions.