Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Saving date and time and getting date
Message
De
24/02/2010 12:17:29
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
01450712
Message ID:
01450793
Vues:
48
>>Hi All,
>>
>>I will create a datetime field. I'll save date and time to it. I need date and time and have filtering just date part. Should I create an index like;
>>
>>CONVERT(char(10),mydate,112)
>>
>>and use;
>>vfp:
>>xmydate=dtoc(date(),1)
>>sql server:
>>where convert(char(10),mydate,112)=?xmydate
>>
>>for performance
>>
>>or is just an index with mydate is enough for performance;
>>
>>vfp:
>>xmydate=date()
>>sql server:
>>where mydate=?xmydate
>
>If this guy is right, just index on the datetime field and then use FLOOR() to access the date part ---
>
>http://www.bennadel.com/blog/122-Getting-Only-the-Date-Part-of-a-Date-Time-Stamp-in-SQL-Server.htm
>
> I am going to try this out myself when I get a chance. Up to now I have always used DATEPART() or an unintuitive (to me) approach involving DATEADD().


That guy is right and could do it in a simpler way:
cast(myDateField as int) = cast( @searchDate as int )
BUT such functions would slow it down IMHO. Simply calculate and use upper/lower values. Otherwise here is another one:
select * from myTable where DateDiff(d, myDateField, @searchDateTime ) = 0
Metin,
You can't index on expression but you can index on computed columns if need be.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform