View previous topic :: View next topic
|
Author |
Message |
CJT
New User
Joined: 02 Aug 2007 Posts: 83 Location: Here
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
CJT
New User
Joined: 02 Aug 2007 Posts: 83 Location: Here
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
CJT
New User
Joined: 02 Aug 2007 Posts: 83 Location: Here
|
|
|
|
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 |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
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 |
|
|
CJT
New User
Joined: 02 Aug 2007 Posts: 83 Location: Here
|
|
|
|
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 |
|
|
|