Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select where DateTime field?
Message
From
17/09/2013 11:13:50
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 6.5 and older
Application:
Web
Miscellaneous
Thread ID:
01583397
Message ID:
01583404
Views:
38
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)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform