View previous topic :: View next topic |
Author |
Message |
Uttank Beginner
Joined: 12 Feb 2004 Posts: 12 Topics: 9
|
Posted: Sun Sep 19, 2004 10:42 pm Post subject: problem of max. number of table references in a query |
|
|
We are using a query in a JCL to get a report. But we are getting an error message that the number of table references in the query is more than 15.
In order to resolve this, we thought of passing value (instead of using a join of tables) from one step of JCL (which would contain the output of the first query) to the SQLINP step of the JCL which contains the final query. In other words, break the query into two and pass value from one query to another. For example,
Query 1 : SELECT aaa FROM bbb WHERE ccc = '123' --> OUTPUT = &var
Query 2 : SELECT mmm FROM nnn WHERE ooo = &var
We do not know how to proceed exactly. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Mon Sep 20, 2004 8:45 am Post subject: |
|
|
Uttank,
You probably need to format the output from the query 1. It can be done but there are many things to be taken into consideration. Any sql query cannot exceed 32767. So if your output from query 1 results in more rows then you need to split the sql once again.
Why don't you code a single program with the following logic?
1. Declare a cursor on the main table(BBB)
2. Fetch the record
3. Look up the record in dependent tables(NNN)
4. Repeat the steps(1-3) until you reach the EOF cursor
Hope this helps...
Cheers
kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
Uttank Beginner
Joined: 12 Feb 2004 Posts: 12 Topics: 9
|
Posted: Mon Sep 20, 2004 10:19 pm Post subject: |
|
|
Thanks for the prompt reply.
For us, the query 1 returns a single value (1 row, 1 column) that we need to use in the query 2. Can you give us the exact syntax in a JCL by which we can pass the output of query 1 to query 2? That's the exact solution we are looking for.
Thanks,
Uttank |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Tue Sep 21, 2004 7:43 am Post subject: |
|
|
Uttank,
You can generate sql statements like as shown here.
Code: |
SELECT CHAR('SELECT aaa FROM DEPENDENT_TABLE')
,CHAR('WHERE COL1 = ')
,CHAR('''')
,column to be selected
,CHAR('''')
,CHAR(';')
FROM MAIN_TABLE
;
|
This will generate a statement like this
Code: |
SELECT aaa FROM DEPENDENT_TABLE WHERE COL1 = 'some value' ;
|
Hope this helps...
Cheers
kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
|
|