View previous topic :: View next topic |
Author |
Message |
enge Beginner
Joined: 12 Oct 2004 Posts: 78 Topics: 39
|
Posted: Tue Sep 15, 2009 9:26 am Post subject: convert "CURRENT DATE" in numeric format and test |
|
|
hello everyone,
i can't test a column of a db2 table using "CURRENT DATE".
for example:
table:
col1
----------
20091015
20091014
20091010
20090909
select count(*) from mytable
where col1 > CURRENT DATE
how can i do?
thanks in advance. |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Tue Sep 15, 2009 9:38 am Post subject: |
|
|
what is the datatype of col1. if it is a datetime datatype, then your sql is ok.
but, probably, col1 is packed-decimal or someother idiot datatype.
so, you have to cast current_date to be the same datatype as col1.
casting col1 to be a date would not be good idea, then db2 must cast every column.
but if you cast the current_date to whatever datatype col1 is, the conversion is only done once. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
enge Beginner
Joined: 12 Oct 2004 Posts: 78 Topics: 39
|
Posted: Wed Sep 16, 2009 3:46 am Post subject: |
|
|
col1 is packed-decimal,unfortunately,and contains numeric values in yyyymmdd format.
so, can you suggest me how to change my sql select casting "CURRENT DATE"? |
|
Back to top |
|
 |
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Wed Sep 16, 2009 10:19 am Post subject: |
|
|
If this is embedded SQL in a COBOL program, convert CURRENT DATE to yyyymmdd format then compare COL1 to the converted CURRENT DATE as Dick suggests. _________________ ....Terry |
|
Back to top |
|
 |
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Wed Sep 16, 2009 10:25 am Post subject: |
|
|
enge, This may work:
Code: |
SELECT integer(
SUBSTR(CHAR(CURRENT DATE),1,4) ||
SUBSTR(CHAR(CURRENT DATE),6,2) ||
SUBSTR(CHAR(CURRENT DATE),9,2))
FROM SYSIBM.SYSDUMMY1;
|
_________________ Thanks,
NASCAR9 |
|
Back to top |
|
 |
enge Beginner
Joined: 12 Oct 2004 Posts: 78 Topics: 39
|
Posted: Wed Sep 16, 2009 10:43 am Post subject: |
|
|
thank for your intervention terry but,
to be accurate .. is an unload from a db2 table such as: Code: |
//STEP0001 EXEC PGM=IKJEFT01,DYNAMNBR=20,COND=(0,NE)
//SYSTSPRT DD SYSOUT=*
//SYSTSIN DD *
DSN SYSTEM(ADG0)
RUN PROGRAM(DSNTIAUL) PLAN(DSNTIAUL) -
LIB('ADG0SYS.RUNLIB.LOAD') PARM('SQL')
END
//SYSPRINT DD SYSOUT=*
//SYSPUNCH DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSIN DD *
SELECT * FROM MYTABLE
WHERE COL1 = date of the day or current date
WITH UR;
//SYSREC00 DD DSN=MYSEQ,
// UNIT=SYSDA,SPACE=(CYL,(50,100),RLSE),
// DCB=BUFNO=15,LRECL=0700,
// DISP=(,CATLG,DELETE)
|
if you take a look at the sentence "date of the day or current date" ,it is just where i have to test COL1 (numeric format) and, somehow, today date... |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12380 Topics: 75 Location: San Jose
|
Posted: Wed Sep 16, 2009 11:16 am Post subject: |
|
|
enge,
Try this sql. I assumed your date has - as the separator character.
Code: |
SELECT *
FROM MYTABLE
WHERE COL1 = DECIMAL(REPLACE(CHAR(CURRENT DATE),'-',''))
WITH UR;
|
|
|
Back to top |
|
 |
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Wed Sep 16, 2009 11:29 am Post subject: |
|
|
Why won't this work? In your first post the data does not contain dashes '-'
Edit: after re-reading the above post, my solution may be cumbersome.
Code: |
select count(*) from mytable
where col1 = (SELECT integer(
SUBSTR(CHAR(CURRENT DATE),1,4) ||
SUBSTR(CHAR(CURRENT DATE),6,2) ||
SUBSTR(CHAR(CURRENT DATE),9,2))
FROM SYSIBM.SYSDUMMY1);
|
_________________ Thanks,
NASCAR9 |
|
Back to top |
|
 |
enge Beginner
Joined: 12 Oct 2004 Posts: 78 Topics: 39
|
Posted: Thu Sep 17, 2009 3:29 am Post subject: |
|
|
awesome,
both got the target.thank you very much |
|
Back to top |
|
 |
|
|