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
Update DB2 file
Moderators: chulett, rschirm, roy
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:
![Confused :?](./images/smilies/icon_confused.gif)
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
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.