Posted by Plamen Ratchev on 07/12/07 23:13
The datetime data type includes both date and time portions. When you set a
datetime value to '4/5/07' (btw, it will be better to use format like
'20070405' to avoid ambiguity in date format), you are effectively setting
the time portion to midnight. So, your condition in plain English is like
"select all rows where ShipDate is after midnight on 4/5/07 and before
midnight on 4/18/07". I assume your ShipDate values have time portion
according to when the shipment occurred. Because of that all rows for 4/5/07
are returned (except if you had a shipment exactly at midnight).
If you want to get all rows between 4/5/07 and 4/18/07 (inclusive), you can
write it like this:
WHERE ShipDate >= '20070405'
AND ShipDate < '20070419'
See more about the datetime data type in the following article by Tibor
Karaszi:
http://www.karaszi.com/SQLServer/info_datetime.asp
HTH,
Plamen Ratchev
http://www.SQLStudio.com
[Back to original message]
|