Re: SQL question on Dates
From: Eric Boukobza <eric_at_johnbryce.co.il>
Date: 1996/05/20
Message-ID: <31A0B20A.3E52_at_johnbryce.co.il>#1/1
Date: 1996/05/20
Message-ID: <31A0B20A.3E52_at_johnbryce.co.il>#1/1
DPepa wrote:
>
> >How would I write the SQL to pull the current month's records without
having
> >to put modify the date in the criteria? Therefore on the first of the
month
> >it would automatically reset to pulling just that month's records.
>
> select * from my_table
> where to_char(sysdate,'mmyyyy') = to_char(my_date,'mmyyyy')
If you have an index on 'my_date' this will not use it. If you have a big table better use:
where my_date > to_date ('01'||to_char(sysdate,'MMYYYY'), 'DDMMYYYY')
it seems tricky but it will use index on my_date.
Eric Boukobza
mailto:eric_at_johnbryce.co.il
Received on Mon May 20 1996 - 00:00:00 CEST