Update DB2 file

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
Raftsman
Premium Member
Premium Member
Posts: 335
Joined: Thu May 26, 2005 8:56 am
Location: Ottawa, Canada

Update DB2 file

Post by Raftsman »

When updating a DB2 file, is there a way to accumulate a count for a field in place of updating the count.

i.e. Key 1 Count = 2

Update

Key 1 Count = 5

Updated record

Key 1 Count = 7

Is there a quick way to do this without reading the DB2 file, doing a lookup, if it exist, calculate the new value and update the record or can I do it all in one step. Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

DB2 'file'? :?

Are you asking if you can update a field in a table without knowing the original value of the field? Do you mean something like this using standard SQL:

Code: Select all

update tablename
set Count = Count + 5
where Key = 1
-craig

"You can never have too many knives" -- Logan Nine Fingers
Raftsman
Premium Member
Premium Member
Posts: 335
Joined: Thu May 26, 2005 8:56 am
Location: Ottawa, Canada

Post by Raftsman »

Yes. When entering the DB2 File Stage, we don't know what the original count is. Normally, update will replace the original value and not accumulate it. Can I manually code the update where Update ....Where... Set Count = Count + Previous_stage.count
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You've answered your own question.

If you don't know what the original count is, and need to know, then the only way is to interrogate the table.

You could do this in a previous job with a query such as

Code: Select all

SELECT KEY,COUNT(*) FROM DB2TABLE GROUP BY KEY;
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply