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 

convert "CURRENT DATE" in numeric format and test

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


Joined: 12 Oct 2004
Posts: 78
Topics: 39

PostPosted: Tue Sep 15, 2009 9:26 am    Post subject: convert "CURRENT DATE" in numeric format and test Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Tue Sep 15, 2009 9:38 am    Post subject: Reply with quote

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
View user's profile Send private message
enge
Beginner


Joined: 12 Oct 2004
Posts: 78
Topics: 39

PostPosted: Wed Sep 16, 2009 3:46 am    Post subject: Reply with quote

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
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Wed Sep 16, 2009 10:19 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Wed Sep 16, 2009 10:25 am    Post subject: Reply with quote

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
View user's profile Send private message
enge
Beginner


Joined: 12 Oct 2004
Posts: 78
Topics: 39

PostPosted: Wed Sep 16, 2009 10:43 am    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Sep 16, 2009 11:16 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Wed Sep 16, 2009 11:29 am    Post subject: Reply with quote

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
View user's profile Send private message
enge
Beginner


Joined: 12 Oct 2004
Posts: 78
Topics: 39

PostPosted: Thu Sep 17, 2009 3:29 am    Post subject: Reply with quote

awesome,
both got the target.thank you very much
Back to top
View user's profile Send private message
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