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

For update of


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

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Fri Oct 05, 2012 4:51 pm
Reply with quote

I have cursor declared as following using the UNION ALL clause. I need to write into a report the details in this cursor. this is why its coded with different union all.

SELECT * FROM Table A WHERE Action = 'INP'
AND Time_STAMP = Current timestamp
AND STATUS= A
UNION ALL
SELECT * FROM Table B WHERE Action = 'BYP'
AND Time_Stamp = Current timestamp
AND STATUS= A
UNION ALL
SELECT * FROM Table B WHERE Action = 'CRT'
AND Time_Stamp = Old timestamp
AND STATUS= A
UNION ALL
SELECT * FROM Table B WHERE Action = 'DEL'
AND Time_Stamp = Old timestamp
AND STATUS= A

Table A looks as follows

Code:


TRANM_ID                ACTION            DATA           TIME_STAMP                STATUS
ABC                     INP               ZZXX           Old Timestamp               A
ABC                     CRT               ZZXX           Old Timestamp               A
ABC                     DEL               ZZXX           Old Timestamp               A


             


As I write each of the rows in the cursor to the report i need to update the STATUS column to C. Can this be acheived in a cursor that uses UNION ALL. please advise?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Oct 05, 2012 6:24 pm
Reply with quote

No,
you have two tables,
(which is why you went to UNION
otherwise, you would have had to qualify the columns)
which would cause the cursor to be declared as READ-ONLY.

That by the way is in the manual.
Back to top
View user's profile Send private message
CJT

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Fri Oct 05, 2012 6:42 pm
Reply with quote

Ok, So would this mean i will need to update the status column to C in a separate query for the given time stamp?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Oct 05, 2012 7:26 pm
Reply with quote

actually,
you would need to use one of two separate UPDATE's,
(one for table A, one for Table B)
remembering of course,
you need to know from which table the row has been selected.

do you have an order by clause in your cursor?
Back to top
View user's profile Send private message
CJT

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Fri Oct 05, 2012 7:50 pm
Reply with quote

Hi Dick,

Please pardon my typo here. the query is only about one table - Table A. Table B was a typo. I am also using Order By

SELECT * FROM Table A WHERE Action = 'INP'
AND Time_STAMP = Current timestamp
AND STATUS= A
UNION ALL
SELECT * FROM Table A WHERE Action = 'BYP'
AND Time_Stamp = Current timestamp
AND STATUS= A
UNION ALL
SELECT * FROM Table A WHERE Action = 'CRT'
AND Time_Stamp = Old timestamp
AND STATUS= A
UNION ALL
SELECT * FROM Table A WHERE Action = 'DEL'
AND Time_Stamp = Old timestamp
AND STATUS= A
Order by Data, Action.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Oct 05, 2012 8:00 pm
Reply with quote

is something wrong with this query (besides the syntax errors I took over):
Code:
SELECT * FROM Table A
WHERE Action in ( 'INP','BYP','CRT','DEL' )
AND Time_Stamp = case when Action in ( 'INP','BYP') then Old timestamp else current timestamp end
AND STATUS= A
Order by Data, Action
Back to top
View user's profile Send private message
CJT

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Mon Oct 08, 2012 11:55 am
Reply with quote

Thanks, but i have one question. Can i make the Stat_C = A for the rows processed from A to C using update clause. I am not well versed with DB2, so if you can advise it would be good help.
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 Read a flat file and update DB2 table JCL & VSAM 2
No new posts how to update an ISR appl var from an... TSO/ISPF 8
No new posts DB2 SQL query to read and update data... DB2 12
No new posts SKIP LOCKED DATA in UPDATE statement DB2 9
No new posts Group comparison/update between two f... DFSORT/ICETOOL 10
Search our Forums:

Back to Top