Question

I am trying to select data from a certain date from range, but not within a certain set of parameters.

Currently:

SELECT external_reporting_id AS asin,
       last_updated          AS "Received"
  FROM transfer_delivery_items
 WHERE last_updated >= TO_DATE(sysdate, 'DD-MON-YY') - 13
 ORDER BY last_updated DESC;

But I would want to see everything NOT in that date range.
I have tried >= TO_DATE(sysdate, 'DD-MON-YY')-13, but it doesn't look like it is an approved format, or even possible if anything can lend me a hand that'd be great.

Was it helpful?

Solution

sysdate is already a date, so if you want everything 13 days prior do:

select external_reporting_id ASIN, last_updated as "Received" 
  from transfer_delivery_items
 where last_updated >= trunc(sysdate) -13
 order by last_updated desc;

The trunc(sysdate) will remove the time from the date, to encompass all records 13 days prior.

Note: I would not do

trunc(last_updated) >= trunc(sysdate) 

because last_updaetd is probably an indexed column and trunc(last_update) will bypass that index. (unless there is a function index on trunc(last_updated).

Update:

To get the block of dates 13 days prior and no more than 13 days into the future do:

select external_reporting_id ASIN, last_updated as "Received" 
  from transfer_delivery_items
 where last_updated >= trunc(sysdate) -13
   and last_updated <= trunc(sysdate) +13
 order by last_updated desc;

OTHER TIPS

It think you can NOT the BETWEEN: http://docs.oracle.com/cd/B28359_01/server.111/b28286/conditions011.htm#SQLRF52147

I don't have an Oracle instance available to me or I'd test this out. I'm pretty sure it will work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top