IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SELECT and UPDATE Multiple rows in a single query with Join


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Rusikesh

New User


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

PostPosted: Sat Feb 18, 2012 6:52 pm
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: 2455
Location: Hampshire, UK

PostPosted: Sat Feb 18, 2012 10:47 pm
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: 275
Location: Mumbai

PostPosted: Mon Feb 20, 2012 9:16 am
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: 6966
Location: porcelain throne

PostPosted: Mon Feb 20, 2012 10:41 am
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

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Mon Feb 20, 2012 7:42 pm
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: 6966
Location: porcelain throne

PostPosted: Tue Feb 21, 2012 12:18 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts RC query -Time column CA Products 3
No new posts Multiple table unload using INZUTILB DB2 2
Search our Forums:

Back to Top