sql server 2008 BETWEEN uses the same logic as >= AND <=

hi experts

this: BETWEEN uses the same logic as >= AND <=
is it true or false?
can you explain me with transact sql code?
enrique_aeoAsked:
Who is Participating?
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
True.  Both return the same number of rows, the BETWEEN ran in 195 ms vs. the >= <= ran in 215ms.


use AdventureWorks2012
GO

SET STATISTICS TIME ON

SELECT *
FROM Sales.SalesOrderDetail
WHERE UnitPrice BETWEEN 5.70 and 8.99
ORDER BY UnitPrice

SELECT *
FROM Sales.SalesOrderDetail
WHERE UnitPrice >= 5.70 AND UnitPrice <= 8.99
ORDER BY UnitPrice

SET STATISTICS TIME OFF
0
 
enrique_aeoAuthor Commented:
please, can you give me the URL this download AdventureWorks2012 database
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
You can download a trial version here:
http://www.microsoft.com/sqlserver/en/us/get-sql-server/try-it.aspx

You should also be able to take the T-SQL you have provided, copy-paste it into the SSMS of any version of SQL server, modify to work with any table, and see for yourself.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
enrique_aeoAuthor Commented:
I refer to this database: AdventureWorks2012
0
 
Éric MoreauSenior .Net ConsultantCommented:
if you check the query plan for 2 queries (1 using BETWEEN and 1 using >= AND <=) you will find that both returns exactly the same thing
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Correct, just saw the execution plan.  I just ran it a couple of times and am getting minor differences in execution time, which must be outside influces so it appears both queries are identical.

>I refer to this database: AdventureWorks2012
Not sure if this is a question.  You can remove the USE and SET STATISTICS lines, as I only included them to illustrate the execution time.  The two SELECT queries provide you with your answer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.