Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using BETWEEN versus >= AND <=

Status
Not open for further replies.

ZABADAK

Programmer
Feb 24, 2005
39
US
In Access 2000 in SQL is there any difference when comparing dates to the efficiency of?

WHERE MYDATE BETWEEN ... AND ...
and
WHERE MYDATE >= ... AND MYDATE <= ...
 
The BETWEEN...AND operator is treated differently in different databases:

1) BETWEEN..AND only selects fields that are between and excludes the test values.

2) BETWEEN..AND selects fields that are between and includes the test values.

3)BETWEEN..AND selects fields between the test values, including the first test value and excluding the last test value.

MS Access uses the 2nd (all inclusive) method.

< M!ke >
 
Thanks for the response, unfortunately it does not throw any light on my question...
 
Sorry, you were looking for the EFFICIENCY difference between the two methods, not the actual values that would be included in them?

My guess is that, because the BETWEEN...AND is a single set of comparison factors and the >=...<= is a double set of comparison factors, the BETWEEN...AND would be more efficient.

Nanoseconds! Who knew they could add up so fast? ;-)


< M!ke >
 
That seems like questionable logic to me. I was hoping someone would know.
 
It's very difficult to get information about how Jet works. Having been brought up on things like DB2 I find this frustrating. You get snippets on the Microsoft site but no complete picture.

Personally I wouldn't have thought there was any difference. I would assume Access would translate BETWEEN into >=/<= before it scanned the index or data pages.

 
I would guess, and it's only a guess, that BETWEEN ... AND would be more efficient (if there's any difference) because it could be be optimized better than the separate >=, <= which could be any two conditions and which would have to be treated in a more general way.
 
That seems like questionable logic to him. He was hoping someone would know.

< M!ke >
 
Because he was hoping someone would know.

Tim

[blue]_____________________________________________________
If you need immediate assistance, please raise your hand.
If you are outside of Raleigh, raise your hand and say
[/blue] [red]Ooh! Ooh![/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top