MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

date parameter in SQL

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
new user
Beginner


Joined: 12 Oct 2004
Posts: 7
Topics: 3

PostPosted: Thu Oct 21, 2004 4:10 am    Post subject: date parameter in SQL Reply with quote

Hi,

In one of my DB2 UNLOAD JCL, the date range is specified in the WHERE clause of the SQL as

WHERE DATE (INSERT_TIMESTAMP) BETWEEN '2003-09-05' AND '2004-09-05'

Is it possible to replace ''2003-10-21' and '2004-10-21' with parameters like <<period begin date>> and <<period end date>> in the SQL
and feed this two dates through a control card in the same JCL step?

Thanks
-new user
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Thu Oct 21, 2004 5:39 am    Post subject: Reply with quote

new user,

why not create the WHERE clause dynamically with your values and concatenate it your sql dd statement.

ie.
UNLOAD STEP
Code:

//SYSIN    DD DSN=SQL STMT DSN,
//                   DISP=SHR
//             DD DSN=DYNAMIC WHERE CLAUSE DSN,
//                  DISP=SHR


Your SQL STMT DSN will have the SELECT clause

And you can create the dynamic where clause DSN in a step above using sort

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
new user
Beginner


Joined: 12 Oct 2004
Posts: 7
Topics: 3

PostPosted: Sun Oct 24, 2004 2:16 am    Post subject: Reply with quote

Hi Kolusu

Thanks for your reply. That was a good suggestion.

But is it possible to achieve something like this :
Code:

//UNLOAD   EXEC PGM=IKJEFT01,DYNAMNBR=100                           
//SYSTSPRT DD SYSOUT=*                                             
//SYSPRINT DD SYSOUT=*                                             
//LISTING  DD SYSOUT=*                                             
//SYSUDUMP DD SYSOUT=*                                             
//SYSPUNCH DD DUMMY                                                 
//SYSREC00 DD DSN=DRN1111.UNL.FILE,             
//     DCB=(RECFM=FB,LRECL=80,BLKSIZE=0),                           
//     DISP=(NEW,CATLG,DELETE),                                     
//     UNIT=DISK,SPACE=(CYL,(50,100))                               
//SYSTSIN  DD *                                                     
   DSN SYSTEM(DB10)                                                 
   RUN PROGRAM(DXUNLOAD) PLAN(DXUNLOAD) LIB('SYS1.DB110.PGM') -   
   PARM('SQL') 
//SYSIN    DD *                                                       
  SELECT    A.SSN,                                         
                 A.CUST_NAME                                   
  FROM                                                                 
                 DB110.ABXY112T.CUST_TABLE A                                         
    WHERE
            DATE (A.INSERT_TIMESTAMP)
                 BETWEEN &BEG_DATE AND &END_DATE ;
//DATECARD DD *
2003102120041021                                               
//*

Thanks
- new user
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Sun Oct 24, 2004 4:44 pm    Post subject: Reply with quote

Newuser,

As I mentioned earlier you need to step to create the dynamic control cards.In this case I added a SORT step to create the date range. Also in DB2 the timestamp is of the format 'YYYY-MM-DD-HH.MM.SS.NNNNNN'. So the date portion would be 'YYYY-MM-DD' which is a total of 10 bytes. So you need to pass your date range in the above mentioned format.

The following JCL will give you the desired results. You need to provide the DATECARD as sortin dataset in step0100.

Code:

//STEP0100 EXEC PGM=SORT                                   
//SYSOUT   DD SYSOUT=*                                     
//SORTIN   DD *                                             
2003-10-212004-10-21                                       
//SORTOUT  DD DSN=&T1,DISP=(,PASS),SPACE=(TRK,(1,1),RLSE)   
//SYSIN DD *                                               
 SORT FIELDS=COPY                                           
 OUTREC FIELDS=(C' BETWEEN ',   $ BETWEEN CLAUSE           
                C'''',          $ OPENING QUOTE             
                1,10,           $ BEGIN DATE               
                C'''',          $ CLOSING QUOTE             
                C' AND ',       $ AND CLAUSE               
                C'''',          $ OPENING QUOTE             
                11,10,          $ END DATE                 
                C'''',          $ CLOSING QUOTE             
                C';',           $ SEMI-COLON
                80:X)           $ PAD SPACES TO 80 BYTES   
/*                                                         
//STEP0200 EXEC PGM=IKJEFT01,DYNAMNBR=100
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSPUNCH DD SYSOUT=*
//SYSREC00 DD DSN=DRN1111.UNL.FILE,
//            DISP=(NEW,CATLG,DELETE),
//            UNIT=DISK,
//            SPACE=(CYL,(50,100),RLSE)
//SYSTSIN  DD *
DSN SYSTEM(DB10)
RUN PROGRAM(DXUNLOAD) PLAN(DXUNLOAD) LIB('SYS1.DB110.PGM') -
    PARM('SQL')
//SYSIN    DD *
SELECT A.SSN,
       A.CUST_NAME
  FROM DB110.ABXY112T.CUST_TABLE A 
 WHERE DATE (A.INSERT_TIMESTAMP)
//         DD DSN=&T1,DISP=OLD
/*


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Manas Biswal
Intermediate


Joined: 29 Nov 2002
Posts: 382
Topics: 27
Location: Chennai, India

PostPosted: Mon Oct 25, 2004 9:20 am    Post subject: Reply with quote

new user,

Instream sysin card takes data specified as is. It cannot resolve symbolics. You have to add a sysin dataset as Kolusu as mentioned.

Thanks,
Manas
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group