Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select where DateTime field?
Message
De
17/09/2013 11:13:50
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 6.5 and older
Application:
Web
Divers
Thread ID:
01583397
Message ID:
01583404
Vues:
37
For roughly 100,000 rows, I would say the difference would be in terms of milliseconds, or maybe a second at the most, certainly not minutes.

I did the following, using the Purchasing.PurchaseOrderHeader table in AdventureWorks:
create index [OrderDate_IX] on Purchasing.PurchaseOrderHeader (OrderDate)

set statistics io on
set statistics time on 

select PurchaseOrderID,OrderDate from Purchasing.PurchaseOrderHeader
   where OrderDate >= '20050517' and OrderDate < '20050518'

select PurchaseOrderID,OrderDate from Purchasing.PurchaseOrderHeader
   where cast(OrderDate as Date) = '20050517'
They both will use an Index Seek, but there is a slight bit of additional overhead using the CAST that results in an increased execution time of anywhere from 20-80 milliseconds. I generally avoid expressions in a WHERE clause where I can - so I would say the first approach is technically better. It's an old trick developers (especially those writing reports) have used for years....to retrieve all the rows that are greater than or equal to midnight of a start date, and less than midnight of (final date that you want, plus one day)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform