Inom datum

Databaser & SQL

1 svar · 481 visningar · startad av Dino

Medlem sedan sep. 20011 914 inlägg
Trådstart#1

SQLServer2005

Är det någon skillnad på:

o.Date BETWEEN @startdate AND @enddate

och

o.Date >= @startdate AND o.Date < dateadd(day,1,@enddate)
Medlem sedan sep. 20011 914 inlägg
#2

Fick svar.

The difference is if you have time portion stored in table by using BETWEEN
caluse you might ge a wrong result as SQL Server 'removes' time portion.
On the other hand with your second approac you WON'T get a wrong data

Also, but you should be testing it, with the second option you may get
betterw performance as SQL Server most likely use and index on the column.I
do not say that it does not with the first one, just test it.

578 ms totalt · 4 externa anrop · v20260731065814-full.d34c6d5a
118 ms — deklarationer (db)
117 ms — hämta statistik (db)
127 ms — hämta tråd, inlägg och bilagor (db)
118 ms — ändringar (db)