mangsk Beginner

Joined: 05 Jun 2004 Posts: 46 Topics: 18
|
Posted: Fri Mar 18, 2005 5:39 am Post subject: Problem about executing same query on number of tables |
|
|
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. _________________ Regards,
Mangsk |
|
SureshKumar Intermediate
Joined: 23 Jan 2003 Posts: 211 Topics: 21
|
Posted: Fri Mar 18, 2005 8:44 am Post subject: |
|
|
Mangsk,
Its not just about doing 50 times but also plan for would be more efficient. You can try dynamic SQL, its going to add to the cost. Maybe, try opening a cursor with a union ALL, like
SELECT 'FROM TABLE 1',COUNT(*)
FROM TABLE 1
UNION ALL
SELECT 'FROM TABLE 2',COUNT(*)
FROM TABLE 2
UNION ALL
SO ON
try it, check for performance. |
|