0
I need to provide information on the hiring anniversaries per week. Exemplifying once a week HR will send a message of congratulations to the hiring birthday.
I created the following SQL query:
SELECT
HIRE_DATE AS DATA_CONTRATACAO,
EXTRACT(DAY FROM HIRE_DATE) AS DIA_CONTRATACAO,
EXTRACT(MONTH FROM HIRE_DATE) AS MES_CONTRATACAO,
SYSDATE AS HOJE,
SYSDATE+7 AS DATA_LIMITE
FROM
EMPLOYEES
WHERE EXTRACT(MONTH FROM HIRE_DATE) = EXTRACT(MONTH FROM SYSDATE)
AND EXTRACT(DAY FROM HIRE_DATE) >= EXTRACT(DAY FROM SYSDATE+7)
There is a logic error because only the separate days we lose the month reference as in the example bettwen.
AND EXTRACT(DAY FROM HIRE_DATE) >= EXTRACT(DAY FROM SYSDATE+7)
One possibility is to use a field calculated in the WHERE clause:
WHERE EXTRACT(MONTH FROM HIRE_DATE)*100 + EXTRACT(DAY FROM HIRE_DATE) BETWEEN EXTRACT(MONTH FROM SYSDATE)*100 + EXTRACT(DAY FROM SYSDATE) AND EXTRACT(MONTH FROM SYSDATE)*100 + EXTRACT(DAY FROM SYSDATE+7)
, or useweek
with the functionDATEPART
.– anonimo
Why multiplied by 100 ?
– Rodrigo Martins de Souza
Create a Month field to compare.
– anonimo