Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 1788
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: 6967
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: 1696
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: 6967
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 Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
No new posts Unable to create multiple files using... mbattu COBOL Programming 3 Fri May 05, 2017 5:35 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
This topic is locked: you cannot edit posts or make replies. SDSF multiple spool datasets extracte... PJAlarcon CLIST & REXX 1 Fri Apr 21, 2017 10:50 pm
No new posts Validating file with multiple header/... mohitsaini DFSORT/ICETOOL 6 Thu Apr 13, 2017 1:53 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us