User Defined Update SQL in DB2 UDB API

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

Post Reply
arnabbora
Participant
Posts: 5
Joined: Wed Jul 29, 2009 7:22 am
Location: Bangalore

User Defined Update SQL in DB2 UDB API

Post by arnabbora »

Hi Everyone,

I am trying to update a DB2 table using user defined SQL. The reason I am using an user defined SQL is that , I need to Update a Field to a New value from its Old value, and in the "Where clause" i need the Old value to pick the proper row.

Here are the fields from the table that I am using:

VALUE_KEY, SERVICE_ID, DIM_KEY, CLIENT_ID, WEEK_KEY.

I need to update VALUE_KEY and SERVICE_ID to new values depending on the existing values of DIM_KEY, CLIENT_ID, WEEK_KEY and VALUE_KEY

So the update sql will be something like ,

UPDATE ATTRIBUTE_TABLE SET VALUE_KEY=?,SERVICE_ID=?
WHERE DIM_KEY=? and CLIENT_ID=? and WEEK_KEY=? and VALUE_KEY=OLD_VALUE_KEY.

I have the OLD_VALUE_KEY(the Old value ,which I need to update to New value) field in the columns list.

Now how can I pass this Old value to the "Where" clause of the query in the DB2 API stage?

When I set the user defined SQL as

UPDATE ATTRIBUTE_TABLE SET VALUE_KEY=VALUE_KEY,SERVICE_ID=SERVICE_ID
WHERE DIM_KEY=DIM_KEY and CLIENT_ID=CLIENT_ID and WEEK_KEY=WEEK_KEY and VALUE_KEY=OLD_VALUE_KEY

it is not updating the value. Can we use the fields like VALUE_KEY=VALUE_KEY in User defined SQL Or we need to handle this in another way?

If someone can help me on this I will be really thankful.

Thanks,
Arnie
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

UPDATE ATTRIBUTE_TABLE SET VALUE_KEY=?,SERVICE_ID=?
WHERE DIM_KEY=? and CLIENT_ID=? and WEEK_KEY=? and VALUE_KEY=?

Where you bind the OLD_VALUE_KEY column into the proper place in the SQL just like every other field.
-craig

"You can never have too many knives" -- Logan Nine Fingers
arnabbora
Participant
Posts: 5
Joined: Wed Jul 29, 2009 7:22 am
Location: Bangalore

Post by arnabbora »

Hi Craig,
Thanks for quick reply.
But, I am not able to see your complete post as the privilege is for only premium members :-(
Could you please make your post public for some time?

Thanks,
Arnie
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Didn't notice this was your first post here and you can't be missing all that much of what I posted, so sure.
-craig

"You can never have too many knives" -- Logan Nine Fingers
arnabbora
Participant
Posts: 5
Joined: Wed Jul 29, 2009 7:22 am
Location: Bangalore

Post by arnabbora »

Hi Craig,
Thank you very much.
It worked..:-)


Regards,
Arnie
Post Reply