Hello,
I am trying to find the proper syntax to obtain records that are from the previous month (from current sysdate) of the previous year. For example, we are now in Feb. 2006 and I would like all records from Jan. 2005. I have this (which parses OK), but does not return the correct records (Jan. 2005):
SUM(CASE WHEN TRUNC(TO_DATE(DIM_DATE.THEDATE),'MONTH') >= TRUNC(TRUNC(SYSDATE,'MONTH')-1,'MONTH') AND TRUNC(TO_DATE(DIM_DATE.THEDATE),'MONTH') <= LAST_DAY(TRUNC(TRUNC(SYSDATE,'MONTH')-1,'MONTH'))
AND (TRUNC(TO_DATE(DIM_DATE.THEDATE),'YYYY') >= TRUNC(TRUNC(SYSDATE,'YYYY')-1,'YYYY')) AND SDK_VISIT.VISIT_TYPE_CODE='I' AND SDK_VISIT.EFFECTIVE_TO_DATE='31-DEC-9999' THEN 1 ELSE 0 END)
Any help would be greatly appreciated.
Thanks.
I am trying to find the proper syntax to obtain records that are from the previous month (from current sysdate) of the previous year. For example, we are now in Feb. 2006 and I would like all records from Jan. 2005. I have this (which parses OK), but does not return the correct records (Jan. 2005):
SUM(CASE WHEN TRUNC(TO_DATE(DIM_DATE.THEDATE),'MONTH') >= TRUNC(TRUNC(SYSDATE,'MONTH')-1,'MONTH') AND TRUNC(TO_DATE(DIM_DATE.THEDATE),'MONTH') <= LAST_DAY(TRUNC(TRUNC(SYSDATE,'MONTH')-1,'MONTH'))
AND (TRUNC(TO_DATE(DIM_DATE.THEDATE),'YYYY') >= TRUNC(TRUNC(SYSDATE,'YYYY')-1,'YYYY')) AND SDK_VISIT.VISIT_TYPE_CODE='I' AND SDK_VISIT.EFFECTIVE_TO_DATE='31-DEC-9999' THEN 1 ELSE 0 END)
Any help would be greatly appreciated.
Thanks.