Friday, March 9, 2012

Reasons to use BETWEEN

Hi all.
I searching for information about the use of BETWEEN or ">=" and "<=".
Which solution is better and how SQL Server manages queries using these
expressions?
Any link, white paper or information will be usefull to me.
Thanks in advance.
Fernando PonteFor DATETIME/SMALLDATETIME queries, >= AND < is a better route.
http://www.aspfaq.com/2280
For inclusive queries involving numeric and character data types, BETWEEN is
fine as long as it is not ambiguous.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Fernando Ponte" <fernandoponte@.uol.com.br> wrote in message
news:84C6ADDD-9486-43F6-87A5-CD725843B630@.microsoft.com...
> Hi all.
> I searching for information about the use of BETWEEN or ">=" and "<=".
> Which solution is better and how SQL Server manages queries using these
> expressions?
> Any link, white paper or information will be usefull to me.
> Thanks in advance.
> --
> Fernando Ponte
>|||They're equivalent. SQL Server internally converts 'BETWEEN' into '>= AND
<='
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"Fernando Ponte" <fernandoponte@.uol.com.br> wrote in message
news:84C6ADDD-9486-43F6-87A5-CD725843B630@.microsoft.com...
> Hi all.
> I searching for information about the use of BETWEEN or ">=" and "<=".
> Which solution is better and how SQL Server manages queries using these
> expressions?
> Any link, white paper or information will be usefull to me.
> Thanks in advance.
> --
> Fernando Ponte
>|||I would say never use BETWEEN, because it is symantically confusing.
Between sounds like the values are excluded, rather than included (to me
anyhow)
column between 1 and 2
or
column => 1 and column <= 2
Plus, so many problems are caused by people not quite understanding what
BETWEEN does, that the other approach screams out that it is best. And like
Adam said, they are mathematically equivalent.
----
Louis Davidson - drsql@.hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"Fernando Ponte" <fernandoponte@.uol.com.br> wrote in message
news:84C6ADDD-9486-43F6-87A5-CD725843B630@.microsoft.com...
> Hi all.
> I searching for information about the use of BETWEEN or ">=" and "<=".
> Which solution is better and how SQL Server manages queries using these
> expressions?
> Any link, white paper or information will be usefull to me.
> Thanks in advance.
> --
> Fernando Ponte
>

No comments:

Post a Comment