Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Fetch for a cursor which has union query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Fetch for a cursor which has union query
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: 436
Location: chennai, India

PostPosted: Thu Aug 25, 2005 11:09 am    Post subject:
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: 436
Location: chennai, India

PostPosted: Thu Aug 25, 2005 2:50 pm    Post subject:
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    Post subject: Re: Fetch for a cursor which has union query
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    Post subject:
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    Post subject: Re: Fetch for a cursor which has union query
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    Post subject: Re: Fetch for a cursor which has union query
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    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 Getting -504 Cursor Name GTT-ARTS-CUR... Robin Sulsona DB2 2 Fri Mar 17, 2017 1:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us