webForumDet fria alternativet
Logga in / Bli medlem

Inom datum

Databaser & SQL

1 svar · 462 visningar · startad av Dino

Medlem sedan sep. 20011 914 inlägg
Frågan#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.

255 ms totalt · 4 externa anrop · v20260731065814-full.05830320
128 ms — deklarationer (db)
0 ms — hämta statistik (cache)
125 ms — hämta tråd, inlägg och bilagor (db)
126 ms — ändringar (db)