Update and Insert using user defined sql in ODBC stage

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
sagarkulkarni_in
Participant
Posts: 11
Joined: Sun Jan 30, 2005 11:42 pm

Update and Insert using user defined sql in ODBC stage

Post by sagarkulkarni_in »

I need to update and insert using a user defined sql in ODBC stage.
It does not work and gives a warning.

If I run the update statement alone or Insert statement alone then it works. Any idea how to get to work both the statements at a time.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: Update and Insert using user defined sql in ODBC stage

Post by chulett »

sagarkulkarni_in wrote:I need to update and insert using a user defined sql in ODBC stage.
No you don't. :wink:

What's wrong with the two link approach that you already know works?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

One stage, two links.

Code: Select all

          HashedFile
               :
               :      inserts
               V     ---------> 
   -->    Transformer          ODBC
                     --------->
                      updates
Hashed File contains keys from target table, lookup determines existence of key in target table, which makes insert/update decision.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
loveojha2
Participant
Posts: 362
Joined: Thu May 26, 2005 12:59 am

Post by loveojha2 »

Why do you want to go the user defined sql way.

Please provide the sql then you are trying to accomoplish, may be we can think of an alternate solution.
Success consists of getting up just one more time than you fall.
sagarkulkarni_in
Participant
Posts: 11
Joined: Sun Jan 30, 2005 11:42 pm

Re: Update and Insert using user defined sql in ODBC stage

Post by sagarkulkarni_in »

There is nothing wrong in going with separate insert and update but wouldnt that increase one more job. That is on one job I will do update where as in other job insert.

Is it possible to have two links in one job...one which updates the database whereas other which inserts. I think thats nlt possible in the same job.
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Re: Update and Insert using user defined sql in ODBC stage

Post by ShaneMuir »

sagarkulkarni_in wrote:There is nothing wrong in going with separate insert and update but wouldnt that increase one more job. That is on one job I will do update where as in other job insert.

Is it possible to have two links in one job...one which updates the database whereas other which inserts. I think thats nlt possible in the same job.
Read Ray's suggestion - this is easily accomplished in the one job. Have the one ODBC stage with 2 inputs, one for inserts and one for updates. Use a transformer with a hash lookup of the key values from the target table to determine whether a record exists and insert or update accordingly.
tagnihotri
Participant
Posts: 83
Joined: Sat Oct 28, 2006 6:25 am

Re: Update and Insert using user defined sql in ODBC stage

Post by tagnihotri »

Also if you have single job with "upsert" option (update + insert) you may end up loosing processing time to check whether it is update or insert. Therefore I will sugesst you to go for two links instead of one.
ShaneMuir wrote:
sagarkulkarni_in wrote:There is nothing wrong in going with separate insert and update but wouldnt that increase one more job. That is on one job I will do update where as in other job insert.

Is it possible to have two links in one job...one which updates the database whereas other which inserts. I think thats nlt possible in the same job.
Read Ray's suggestion - this is easily accomplished in the one job. Have the one ODBC stage with 2 inputs, one for inserts and one for updates. Use a transformer with a hash lookup of the key values from the target table to determine whether a record exists and insert or update accordingly.
loveojha2
Participant
Posts: 362
Joined: Thu May 26, 2005 12:59 am

Post by loveojha2 »

Also if you have single job with "upsert" option (update + insert) you may end up loosing processing time to check whether it is update or insert. Therefore I will sugesst you to go for two links instead of one.
That is again based on the case by case.

Say for e.g., if you are bringing the data from a transaction table and you are quite sure of more inserts than updates or the other way around. In those cases it would be better to go with one link instead of two.
Success consists of getting up just one more time than you fall.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

This is my personal opinion, so keep that in mind. :wink:

I've never seen a situation where 'one link' was better than two. Best, IMHO, to take the time to determine what needs to be done with each row and handle each accordingly. Those dual-action updates actions are evil. :twisted:
-craig

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