Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
SELECT and UPDATE Multiple rows in a single query with Join

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Rusikesh

New User


Joined: 04 Feb 2010
Posts: 22
Location: United States

PostPosted: Sat Feb 18, 2012 6:52 pm    Post subject: SELECT and UPDATE Multiple rows in a single query with Join
Reply with quote

Hello All,

How can we Select and Update the multile rows in single SQL query.

I am trying in below way,
I opened a cursor and selected required rows by using Join and on some where condition, now i want to update the selected rows with some status. Also the selected rows i will use for further processing, have written below query, I am using DB2V9.

Can any body look into this and let me know where i missed out.
Code:
DECLARE CURONE CURSOR FOR
SELECT           A.TAB1F1             
                ,A.EMP_ID             
                ,B.EMP_SAL           
                ,B.EMP_INCR           
FROM             TABLE1 A             
LEFT OUTER JOIN TABLE2 B ON           
                 A.TAB1F1= B.TAB2F1   
       AND       A.EMP_STA = '03'     
           UPDATE TABLE1             
           SET A.EMP_STA = '55'       
    WHERE        A.EMP_STA = '03'     
      AND        B.BR_STA_CD = '00'   
      AND        A.EMP_ID = '1111'   
 ORDER BY        A.TAB1F1 DESC       
                ,A.EMP_ID ASC         




Thanks
Rushi.
Back to top
View user's profile Send private message

Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1932
Location: UK

PostPosted: Sat Feb 18, 2012 10:47 pm    Post subject:
Reply with quote

What do you mean 'missed out'? Did you try the query and it failed, or what? Have you got any error messages that you might like to share with us? Or sample data?
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 269
Location: Mumbai

PostPosted: Mon Feb 20, 2012 9:16 am    Post subject:
Reply with quote

Hi Rushikesh,

Please share your error message and why there is ORDER BY clause on UPDATE query?

Regards,
Chandan
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Mon Feb 20, 2012 10:41 am    Post subject:
Reply with quote

unless the syntax has changed in vsn 9 and 10

the UPDATE for a cursor is a separate invocation of SQL

and

a JOINed cursor was read only.

Chandan's comment about an ORDER BY clause in a cursor for UPDATE is also relevant.

Rusikesh,
suggest you refer to the manual,
and don't bother us again until you have resolved your pre-compile errors
or run-time errors if you are attempting to execute this thru spufi or qmf.

last but not least, if you are using db2 for servers/pc/unix,
go to another forum.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1827
Location: NY,USA

PostPosted: Mon Feb 20, 2012 7:42 pm    Post subject:
Reply with quote

You have to go with scrollable cursors which works on ROWSET concept.
Here you can pull all the data once thru ROWSET and then UPDATE them once thru again ROWSET.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Tue Feb 21, 2012 12:18 am    Post subject:
Reply with quote

Rohit Umarjikar wrote:
You have to go with scrollable cursors which works on ROWSET concept.
Here you can pull all the data once thru ROWSET and then UPDATE them once thru again ROWSET.


only if the TS is able to define an UPDATEable cusor,
which he has not.
he has a read only cursor,
so your answer is: WRONG!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts Merging 2 records at multiple rows wi... Bijesh DFSORT/ICETOOL 2 Wed Dec 06, 2017 1:50 am
No new posts Can we combine the rows with same key... V S Amarendra Reddy DB2 12 Fri Dec 01, 2017 10:29 pm
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us