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

Problem about executing same query on number of tables


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts Generate random number from range of ... COBOL Programming 3
No new posts RC query -Time column CA Products 3
Search our Forums:

Back to Top