Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search 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
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
References
priya

Moderator


Joined: 24 Jul 2003
Posts: 624
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: 200
Location: Keane India Ltd., Hyderabad

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
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1