MVSFORUMS.com A Community of and for MVS Professionals
View previous topic :: View next topic
Author
Message
prog_mario Beginner Joined: 08 Sep 2007 Posts: 86 Topics: 27
Posted: Fri Jul 30, 2010 9:13 am Post subject: How to compare a CHAR to a CURRENT DATE
Hello, I need to perform the following query:
SELECT COUNT(*)
FROM TABLE
WHERE COLUMN >= CURRENT DATE - 6 MONTHS;
In this case COLUMN is a CHAR(8) formatted as YYYYMMDD.
Thanks.
Back to top
dbzTHEdinosauer Supermod Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
Posted: Fri Jul 30, 2010 9:41 am Post subject:
char(date_expression,ISO)
ISO
Code:
where column >= substr(char(current_date - 6 months, ISO),1,4) ||
substr(char(current_date - 6 months, ISO),6,2) ||
substr(char(current_date - 6 months, ISO),9,2)
above is untested.
easily tested in spufi:
Code:
select substr(char(current_date - 6 months, ISO),1,4) ||
substr(char(current_date - 6 months, ISO),6,2) ||
substr(char(current_date - 6 months, ISO),9,2)
, length(substr(char(current_date - 6 months, ISO),1,4) ||
substr(char(current_date - 6 months, ISO),6,2) ||
substr(char(current_date - 6 months, ISO),9,2)
)
from sysibm.sysdummy1
the above should return
yyyymmdd 8 _________________ Dick Brenholtz
American living in Varel, Germany
Back to top
jim haire Beginner Joined: 30 Dec 2002 Posts: 140 Topics: 40
Posted: Fri Jul 30, 2010 9:47 am Post subject:
Untested:
Code:
SELECT count(*) FROM TABLE
WHERE SUBSTR(COLUMN,1,4) || '-' || SUBSTR(COLUMN,5,2) || '-' ||
SUBSTR(COLUMN,7,2) >= CHAR(CURRENT DATE - 6 MONTHS)
Back to top
prog_mario Beginner Joined: 08 Sep 2007 Posts: 86 Topics: 27
Posted: Fri Jul 30, 2010 9:56 am Post subject:
Thanks a lot everybody. It worked. _________________ The more I learn, the more I want to learn.
Back to top
dbzTHEdinosauer Supermod Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
Posted: Fri Jul 30, 2010 9:58 am Post subject:
jim, you sql works,
but you are executing a multi-substring on the column for every row,
where as I attempted to only execute the scalar functions 1 time. _________________ Dick Brenholtz
American living in Varel, Germany
Back to top
kolusu Site Admin Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Back to top
dbzTHEdinosauer Supermod Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
Posted: Fri Jul 30, 2010 10:47 am Post subject:
Kolusu,
mind like a steel trap, you have! _________________ Dick Brenholtz
American living in Varel, Germany
Back to top
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