Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select by Date from DateTime in SQL Server
Message
De
11/08/2017 15:48:34
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01653212
Message ID:
01653248
Vues:
64
>>>Hi,
>>>
>>>I am working with the SQL Server database. The field/column is DateTime. And I want to get records by the following criteria:
>>>
>>>
>>>select * from MyTable where DateTimeCol <= '20170810'  
>>>
>>>
>>>Since the DateTimeCol has both the date and time, the above will select 0 records.
>>>
>>>How should I change the WHERE to make sure that only the Date of DateTime is considered and therefore the records where the Date is '20170810' are returned?
>>
>>Simply:
>>
>>
>>select * from MyTable where DateTimeCol < '20170811'  
>>
>
>Thank you, Cetin. It is just that my existing code already uses the Less Than or Equal (not Less Than) and the approach suggested by Martina (cast DateTimeCol as date) works perfectly.


From my POV, changing code from LTE to LT is easier than converting it to use a cast() statement and it is portable, version independent, doesn't have the unneccassry conversion overhead etc. Anyway it is your code.
Ç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
Répondre
Fil
Voir

Click here to load this message in the networking platform