Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Saving date and time and getting date
Message
De
26/02/2010 09:26:52
 
 
À
26/02/2010 09:17:44
Metin Emre
Ozcom Bilgisayar Ltd.
Istanbul, Turquie
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
01450712
Message ID:
01451225
Vues:
36
>>Metin,
>>
>>In SQL Server you can not create an index using a function. Use a date range when looking for a date, e.g.
>>
>>select * from myTable where DateField >=@Today and DateField < @Tomorrow
>>
>
>Thank you all,
>I'll use Naomi's way. I use in first variable today 00:00 and second variable today 24:59:59 . I'm afraid of about performance in other ways. I'm not sure if sql server will use index with other ways...

It will, if you use a field on the left side of the expression and whatever you want at the right side.
BTW there is no such time 24:59:59 :-)

I strongly recommend you to use Naomi's suggestion:
select * from myTable where DateField >=@Today and DateField < @Tomorrow --- Se here is only less that, not less than or equal
Because SQL Server keeps milliseconds also you may filter some records if you use this:
select * 
      from myTable
where DateField >=@Today and DateField <= @TodayAtMidNight
You may have this records:
01/01/2010 23:59:59.937 and that record will be filtered.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform