Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
BitShift
Yak Posting Veteran
98 Posts |
Posted - 2007-10-24 : 11:20:49
|
| when doing a compare with two dates in sql, is BETWEEN not the most efficient way to do it ? |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-24 : 11:25:27
|
| why not?you might try to write explict boundires like value >= @Var and value <= @varso that the parser doesn't have to translate between.. but that's not a real perf gain._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-24 : 11:47:52
|
There is a little gain by using >= and < when comparing dates.When you use BETWEEN, you also set the limits for the search. This can be hard to set when searching for a full day (remember the 3.33 millisecond rounding).If you use >= '20071024 00:00:00' AND < '20071025 00:00:00', you will get ALL records for today.When using BETWEEN '20071024 00:00:00' AND '20071025 00:00:00', you also will get all records for today PLUS the records for tomorrow which have "00:00:00" as time information. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-25 : 02:16:40
|
quote: Originally posted by BitShift when doing a compare with two dates in sql, is BETWEEN not the most efficient way to do it ?
It depends. If you want to inlcude both the ranges, then use itMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|