Question

I have got an example query like

  select cu.customer_no
  from customers.cu 
  where cu.audit_date like '01-FEB-14'

The problem is that I would like to retrieve data only for specific dates which are the first day of the month and skip all of them in between. The desired query should be something like

  select cu.customer_no
  from customers.cu 
  where cu.audit_date like ('01-FEB-14', '01-JAN-14', '01-MAY-14')
Was it helpful?

Solution

Assuming that audit_date is a date, not a varchar2, if you are certain that the time component is always midnight, you can do

WHERE cu.audit_date = trunc(cu.audit_date, 'MM')

If there may be a non-midnight time component and you want to ignore the time component, you can do

WHERE trunc(cu.audit_date) = trunc(cu.audit_date, 'MM')

Alternately, you can use to_char

WHERE to_number( to_char( cu.audit_date, 'DD' ) ) = 1

OTHER TIPS

    select cu.customer_no
    from customers.cu 
    where cu.audit_date 
    in  (select distinct trunc(audit_date ,'MM') from customers);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top