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: 1868
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: 6968
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: 1788
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: 6968
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 Conditional highlighting of rows in I... packerm CLIST & REXX 2 Thu Sep 21, 2017 6:50 pm
No new posts ejck thru rexx to multiple jobs insid... Susanta All Other Mainframe Topics 5 Tue Sep 19, 2017 1:39 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts More than 1 Include criteria for sing... Roy Ware SYNCSORT 6 Wed Sep 13, 2017 11:45 pm

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