datos de Oracle entre fechas

I have to get data from an Oracle Database that are 2 weeks older from to-date.

Its a complex query and I have this condition in the where clause.

I have tried to use between. But in vain . I am sure I'm making some silly mistake in working out the between.

to_date(to_char(sysdate,'yyyy') || to_char(sgs.status_Date,'mmdd'),'yyyymmdd' )
    between (trunc(sysdate)) and trunc(sysdate) - 14

Cualquier ayuda sería muy apreciada.

preguntado el 28 de agosto de 12 a las 14:08

Is this some kind of anniversary calculation? You're taking the day+month from sgs.status_Date, but using the year from sysdate? -

2 Respuestas

As @valex says, you need to swap the order of the expressions. As the documentación para el BETWEEN condición dice:

... the value of

expr1 BETWEEN expr2 AND expr3

is the value of the boolean expression:

expr2 <= expr1 AND expr1 <= expr3

Your version has

your_date between trunc(sysdate) and (trunc(sysdate) - 14)

que es equivalente a

trunc(sysdate) <= your_date and your_date <= (trunc(sysdate) - 14)

... which can never be true - your_date would have to simultaneously be después de hoy, y antes de que hace dos semanas.

Respondido 28 ago 12, 14:08

You should change BETWEEN dates as soon sysdate-14 < sysdate and should be first

to_date(to_char(sysdate,'yyyy') || to_char(sgs.status_Date,'mmdd'),'yyyymmdd' ) 
between (trunc(sysdate) - 14) and (trunc(sysdate)) 

Respondido 28 ago 12, 14:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.