Posted: Thu Oct 21, 2004 4:10 am Post subject: date parameter in SQL
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?
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Sun Oct 24, 2004 4:44 pm Post subject:
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
/*
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