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

Determining input and output fields in a SELECT statement


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
obner

New User


Joined: 18 Jan 2006
Posts: 11

PostPosted: Fri Nov 16, 2007 8:48 am
Reply with quote

Hi,

How can I determine programatically all input and output fields of a SELECT statement? Is there any DB2 function for this?

Thanks,
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Nov 16, 2007 9:13 am
Reply with quote

Hello,

Please clarify your question.

An sql select doesn't have "input" and "output" fields.

If you show a small example, we may be able to provide answers.

Keep in mind that while your question is quite clear to you, it may not be to others.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Fri Nov 16, 2007 9:13 am
Reply with quote

Given the following 2 queries, what would you define as the inputs and the outputs?

Code:
 
SELECT *
FROM TABLE
WHERE COLA > 0 AND COLB < 100000 OR COLC = 100
ORDER BY COLA
FOR READ ONLY WITH UR;

SELECT COLA, COLB, COLD, COLE, COLF, SUM(1)
FROM TABLE
WHERE COLA > 0 AND COLB < 100000 OR COLC = 100
HAVING SUM(1) > 1
GROUP BY COLA, COLB, COLD, COLE, COLF
ORDER BY COLA
FOR READ ONLY WITH UR;


A simple, but not always applicable answer is:
Anything between SELECT and FROM would be the output fields. If you have scalars or a *, it won't be easy to figure them out. The input is anything between the WHERE and the next non-logic keyword (AND/OR)and also anything between HAVING and the next non-logic keyword. But would you consider an ORDER BY or GROUP BY an input to the statement?
Back to top
View user's profile Send private message
obner

New User


Joined: 18 Jan 2006
Posts: 11

PostPosted: Fri Nov 16, 2007 11:32 am
Reply with quote

Hi,

From the select statement below I consider COLA, COLB, COLD, COLE, COLF, SUM(1) as output fields and COLA > 0 AND COLB < 100000 OR COLC = 100 as input fields.

SELECT COLA, COLB, COLD, COLE, COLF, SUM(1)
FROM TABLE
WHERE COLA > 0 AND COLB < 100000 OR COLC = 100

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

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Fri Nov 16, 2007 6:42 pm
Reply with quote

But the ORDER BY, HAVING, and GROUP BY statements mention some field in the database and also affect how the output looks, so doesn't that make them input as well? Also, what about the first statement?

Here is one more. What are you input and output fields in this case? This is a slightly modified version of a production query we have in my shop. I haven't seen anything that can figure this sort of thing out automagically.
Code:

SELECT  A.TICKET_ID                                 
        ,A.TICKET_SRC_CD                             
        ,A.LAST_USER_ID                             
        ,A.TICKET_STATUS_CD                         
        ,A.ACCESS_ID                         
        ,DATE(A.FIRST_EFF_TS) AS CLOSED_DT           
        ,A.RECEIVED_TS                               
        ,A.SPONSOR_ID                                 
FROM TBQUAL.TICKET_T A                           
JOIN (SELECT Y.TICKET_ID, Y.FIRST_EFF_TS             
      FROM TBQUAL.TICKET_T Y                     
      JOIN (SELECT Z.TICKET_ID,                     
                   MIN(Z.FIRST_EFF_TS) AS minEFFDATE 
            FROM TBQUAL.TICKET_T Z               
            WHERE Z.TICKET_STATUS_CD = 'C'           
            GROUP BY TICKET_ID) MT                   
            ON Y.TICKET_ID = MT.TICKET_ID           
            AND Y.FIRST_EFF_TS = MT.minEFFDATE) B     
      ON A.TICKET_ID = B.TICKET_ID                 
      AND A.FIRST_EFF_TS = B.FIRST_EFF_TS             
WHERE DATE(A.FIRST_EFF_TS) >= (CURRENT date - 45 DAYS)
    WITH UR;
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Nov 16, 2007 9:21 pm
Reply with quote

Hello,

I believe the answer to your original question is that - no, you cannot find that programmatically (at least not easily - you would have to write a new sql syntax parser).

There is also no built-in command to do this.
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 TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top