Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a RECID,regionID, areaID ,UserID ,AppNo, NextAppNo(Accepts null)

and data is as follow

(NextApp is in the first row only)
1,102,Ar-1,xyz,1,1
2,102,Ar-1,,erer,2
3,102,Ar-1,tyty,3
4,102,Ar-1,tyty,4

1)
now i want to add another record
what i am doing is
first getting the max number of APPID where areaID = Ar-1 and regionID =102
and then check that if max appNo we got from query is 0 then add nextappNo otherwise not
and then inserting into db now is it possible to do it in one query


2)

now i want to delete the first record what i am doing now is first selecting data where areaID = Ar-1 and regionID =102

and now in loop i check if Recid is the same id we want to delete.
and from there onward i update the the column approver and also if the record which we are going to delete has approverNO = 1 then also update the next approver to one of the next record.
then delete the record from table.

Reply if anything is unclear which i am expexting from my bad english.
Posted
Updated 14-Jan-14 19:57pm
v4
Comments
Maciej Los 14-Jan-14 12:47pm    
Sorry, but your question is not clear.... First you want to add, then to delete. Why? Please be more specific and provide more details. I don;t see APPID field in your table...
Jörgen Andersson 14-Jan-14 23:55pm    
Can you update the example data with <null> where applicable. It's unclear which fields have data or not.
agha_ali22 15-Jan-14 2:04am    
see the updated question

1 solution

You can't do that in one query. You CAN do it in one stored procedure, which can have as many operations in it as you like.
 
Share this answer
 
Comments
agha_ali22 15-Jan-14 1:58am    
i did update and retrive from same query and it is working fine in db2 command line, but not in java
Christian Graus 15-Jan-14 17:05pm    
I don't understand. DB2 is a database, Java is not. The answer is the same, if you want to do many database actions in one call, use a stored procedure, and consider transactions if you want your changes to be atomic.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900