query based on conditon???

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

ahmedwaseem2000
Premium Member
Premium Member
Posts: 145
Joined: Fri Sep 15, 2006 12:23 pm

query based on conditon???

Post by ahmedwaseem2000 »

Hi,

How do i write different queries based on different conditions within db2 stage? i have a column based on which i need to write 3 insert queries and 1 update query is it possible without using multiple db2 stages or transformer?????
gbusson
Participant
Posts: 98
Joined: Fri Oct 07, 2005 2:50 am
Location: France
Contact:

Post by gbusson »

Well, the upsert is useful.but you have only one insert.

Other solution : load your rows in a staging table in DB2, with a code defining the query (ex: 1 for the update, 2 for insert 1).

Then launch a SQL script to make your different queries
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Depending upon the conditions, build your insert/update logic and load it to a file (.sql). Then execute the .sql file from command line which you can do in after job subroutine using ExecSh.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
swades
Premium Member
Premium Member
Posts: 323
Joined: Mon Dec 04, 2006 11:52 pm

Post by swades »

so you have any constrains to do this insert/update action.I mean any particular order issue like first update and then insert etc.?
ahmedwaseem2000
Premium Member
Premium Member
Posts: 145
Joined: Fri Sep 15, 2006 12:23 pm

Post by ahmedwaseem2000 »

Yes, Now i need to set the predcedence, I would want to run the update first and then insert. How do i do that????
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

      ----->  DB2 (update only)
               :
               : (reject)
               :
               V
              DB2 (insert or update)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ahmedwaseem2000
Premium Member
Premium Member
Posts: 145
Joined: Fri Sep 15, 2006 12:23 pm

Post by ahmedwaseem2000 »

I cant see the code......
swades
Premium Member
Premium Member
Posts: 323
Joined: Mon Dec 04, 2006 11:52 pm

Post by swades »

ahmedwaseem2000 wrote:I cant see the code......
because you are not premium member,
can you tell us more about condition,and sequence path.
ahmedwaseem2000
Premium Member
Premium Member
Posts: 145
Joined: Fri Sep 15, 2006 12:23 pm

Post by ahmedwaseem2000 »

Well, In a table there is a row with a flag and expiry timestamp column. which, I would want to expire by updating the flag to N and current timestamp to the expiry date column and then insert a new row with an active flag. to achieve this i tried upsert but it is inserting the row but not updating the previous row. do you know why????
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You have to do inserts and updates seperately. Not in one query.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ahmedwaseem2000
Premium Member
Premium Member
Posts: 145
Joined: Fri Sep 15, 2006 12:23 pm

Post by ahmedwaseem2000 »

Well, I have written both the queries in DB2 UDB stage with upsert option selected but that doesnt work. Does that mean that in upsert either insert or update works and never both together. Incase, if i want to do it within the same DB2 UDB stage how am i going to do that???
swades
Premium Member
Premium Member
Posts: 323
Joined: Mon Dec 04, 2006 11:52 pm

Post by swades »

Are you using DB2UDB Enterprise Stage ?

If yes then
set Write method = Upsert then
set Upsert Mode=User-defined Update & Insert or other option as per your requirement.

Thanks
ahmedwaseem2000
Premium Member
Premium Member
Posts: 145
Joined: Fri Sep 15, 2006 12:23 pm

Post by ahmedwaseem2000 »

Well, I have already done that, But still of no use.
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

What is the prcedence in your upsert? Paste you SQL statement. Unless you are inserting and updating the same record there should not be any issue..
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
ahmedwaseem2000
Premium Member
Premium Member
Posts: 145
Joined: Fri Sep 15, 2006 12:23 pm

Post by ahmedwaseem2000 »

Yes, I am inserting and updating the same record. will that be an issue???
Post Reply