Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

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?
0
enrique_aeo
Asked:
enrique_aeo
  • 3
  • 2
3 Solutions
 
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
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
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

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now