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

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
olgc
Participant
Posts: 145
Joined: Tue Nov 18, 2003 9:00 am

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

Post 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,
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

How are you actually doing this "search"?
-craig

"You can never have too many knives" -- Logan Nine Fingers
olgc
Participant
Posts: 145
Joined: Tue Nov 18, 2003 9:00 am

Post by olgc »

The code is

SELECT * FROM IDBA.PLAYER WHERE PLAYER.FIRSTNAME=? AND PLAYER.LASTNAME=? AND PLAYER.POSTALCODE=?
ketfos
Participant
Posts: 562
Joined: Mon May 03, 2004 8:58 pm
Location: san francisco
Contact:

Post 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
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply