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
 

 

Problem about executing same query on number of tables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
mangsk

New User


Joined: 14 Mar 2005
Posts: 2

PostPosted: Fri Mar 18, 2005 3:56 pm    Post subject: Problem about executing same query on number of tables
Reply with quote

Hi All,
My requirement is - I've to execute the same query
e.g. say
EXEC SQL
SELECT COUNT (*)
INTO :WS-COUNT
FROM table-name
on 50 different tables in a COBOL program and process the count after each time.
Is there any way to do it other than writing the same query 50 times? The table names I've already stored in an array. I tried out defing a variable as WS-TBL-NAME in which I'll move the table name from array and use this variable in FROM. But it doesn't work.
Please advice.

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

priya

Moderator


Joined: 24 Jul 2003
Posts: 568
Location: Bangalore

PostPosted: Sun Mar 20, 2005 1:39 am    Post subject:
Reply with quote

Why not you try Dynamic SQL to do this.
Back to top
View user's profile Send private message
mangsk

New User


Joined: 14 Mar 2005
Posts: 2

PostPosted: Mon Mar 21, 2005 8:57 am    Post subject: Re: Problem about executing same query on number of tables
Reply with quote

The requirement doesn't allow us to use dynamic SQLs.

regds,
Mangsk
Back to top
View user's profile Send private message
ovreddy

Active User


Joined: 06 Dec 2004
Posts: 211
Location: Keane Inc., Minneapolis USA.

PostPosted: Mon Mar 21, 2005 12:41 pm    Post subject:
Reply with quote

Hi All,

As I know EXECUTE SQL IMMEDIATE statement wont work with SELECT statement. But still you can use EXECUTE SQL PREPARE to do this.

I hope the following will work...


MOVE "SELECT count(*) into :WS-COUNT FROM ?" to sql-to-execute.

EXEC SQL
PREPARE FLSQL FROM :Sql-to-execute;
END-EXEC.

MOVE "TABLE1" TO WS-PARM1.

EXEC SQL
EXECUTE FLSQL USING :WS-PARM1.
END-EXEC.

I am not sure that above code will work. So please Test it and let me know the result.


Thanks,
Reddy.
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SYMNAMES problem jacobdng DFSORT/ICETOOL 7 Thu Dec 22, 2016 7:47 am


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