Monday, February 24, 2014

SQL for peoplesoft date values

Current Date

I needed a way to reset a table where the effective date was today. I had a query that worked with TO_DATE('24-02-19','yy-MM-dd') except every day I'd have to update the query to match the current date. Sometimes I'd forget and delete some values I may have wanted. In oracle if you use any current date function like sysdate, current_date etc the current time is actually included. To day where effective date is equal to the current_date would never match unless you ran the query at exactly midnight to the millisecond of the day you wanted removed.

Proof

select to_char(CURRENT_DATE, 'dd-mon-yyyy hh24:mi:ss') from dual;

To get around this I used the TRUNC function to zero everything after the the Date.

Example

select to_char(trunc(CURRENT_DATE,'DDD'), 'dd-mon-yyyy hh24:mi:ss')
from dual;
-- The delete statement would like like this.
delete from PS_MCM_SNLF_H_REC 
where EFFDT = trunc(CURRENT_DATE,'DDD');

No comments:

Post a Comment