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

Fetch for a cursor which has union query


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

New User


Joined: 20 Aug 2005
Posts: 5
Location: hyderabad

PostPosted: Thu Aug 25, 2005 10:17 am
Reply with quote

Hi ALL,

I have declared a cursor which looks like

Declare c1 cursor for
select A1,A2,A3
.
.
unoin
Select A1 B2 A3
.
.
Here A1, A3 are from same tables and A2, B2 are from different tables.


Now i want to know during fetch how should i declare.

I declare has fetch
in to :A1,:A2,:A3,:A4
is it correct or please correct me

As it is uion for every fetch it will have only 3 columns.

Thanks
JR
Back to top
View user's profile Send private message
radhakrishnan82

Active User


Joined: 31 Mar 2005
Posts: 435
Location: chennai, India

PostPosted: Thu Aug 25, 2005 11:09 am
Reply with quote

As it will return one record per fetch,
Fetch
into
:A1
:A2
:A3

is correct.the same is used in our shop.
Back to top
View user's profile Send private message
radhakrishnan82

Active User


Joined: 31 Mar 2005
Posts: 435
Location: chennai, India

PostPosted: Thu Aug 25, 2005 2:50 pm
Reply with quote

now i got you Q.

I think it can't be used like that even if A2 and B2 are of same data type.It will return only 3.
If A2 and B2 are of different data type then UNION itself cant be used.
Back to top
View user's profile Send private message
jayaramreddy.r

New User


Joined: 20 Aug 2005
Posts: 5
Location: hyderabad

PostPosted: Fri Aug 26, 2005 10:00 am
Reply with quote

jayaramreddy.r wrote:
jayaramreddy.r wrote:
Hi ALL,

I have declared a cursor which looks like

Declare c1 cursor for
select A1,A2,A3
.
.
unoin
Select A1 B2 A3
.
.
Here A1, A3 are from same tables and A2, B2 are from different tables.

Sorry

i declare has fetch into
:A1,:A2,:A3,:B2

at every fetch one record into

a1,a3 and b2 or a2

let me know

regards
Jr


Now i want to know during fetch how should i declare.

I declare has fetch
in to :A1,:A2,:A3,:A4
is it correct or please correct me

As it is uion for every fetch it will have only 3 columns.

Thanks
JR


Hi RK

Then please let me know how to declare fetch.

i declared as

Fetch
A1,A2,A3,B2

at time it will fetch A1,A3, and B2 or A2

i mean for every fetch there will three colums only and one colums will be spaces is it works
let me know

thanks
jayaram
Back to top
View user's profile Send private message
atik

New User


Joined: 29 Jul 2005
Posts: 20

PostPosted: Fri Aug 26, 2005 2:10 pm
Reply with quote

HI,
You are using Union means the column nos should be same. while fetching you are bothered about the number of columns not the table from which the data is coming. SO use 3 host variables.
Back to top
View user's profile Send private message
harinatha

New User


Joined: 24 Jul 2005
Posts: 28

PostPosted: Fri Aug 26, 2005 10:36 pm
Reply with quote

Hi,

I agree with atik. What he is saying is correct.

Thanks & Regards,
Hari.
Back to top
View user's profile Send private message
jayaramreddy.r

New User


Joined: 20 Aug 2005
Posts: 5
Location: hyderabad

PostPosted: Mon Aug 29, 2005 11:36 am
Reply with quote

harinatha wrote:
Hi,

I agree with atik. What he is saying is correct.

Thanks & Regards,
Hari.


But how can i differenciate A2 or B2 to write in to file

regards
jr
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 RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Fetch data from programs execute (dat... DB2 3
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
Search our Forums:

Back to Top