How do I use a EJBQL between query with two identical dates?
I have a JPA named query that takes two dates in order to return records with a date column entry between the two dates.
If I enter the same date for both the start and end dates it returns no rows, even though there are records for tha开发者_如何学Got date.
Is there way to make the query work or shall I just run another query when the two dates are the same?
Here's the query:
select o from CustomerOrder o
where o.orderDate between :date_from and :date_to
order by o.orderDate desc
I tend to run all my queries as:
select fld from tbl
where date >= &start_date
and date <= &end_date;
I rarely use between
- the DBMS I use has the same perormance irrespective of which of those methods is used.
My advice would be to do some timings to see if there's no performance degradation to using where ... and
instead of where ... between
and then switch if not.
Some DBMS' actually exclude the "endpoints" (first and/or last) which is probably what you're seeing. The two-clause SQL statement should not have that problem.
精彩评论