IdNameRegisterDate1澎澎2007/1/5 00:00:002丁丁2007/1/6 04:37:003亞亞2007/1/7 00:00:00資料庫的數據如上。若以RegisterDate為查詢條件,找出'丁丁'這條記錄,則查詢語句為SELECT ID, Name, RegisterD...
Id | Name | RegisterDate |
1 | 澎澎 | 2007/1/5 00:00:00 |
2 | 丁丁 | 2007/1/6 04:37:00 |
3 | 亞亞 | 2007/1/7 00:00:00 |
資料庫的數據如上。若以RegisterDate為查詢條件,找出'丁丁'這條記錄,則查詢語句為
SELECT ID, Name, RegisterDate FROM Customer WHERE (RegisterDate BETWEEN '2007-01-06 0:00:00' AND '2007-01-06 23:59:59')
或者為
SELECT ID, Name, RegisterDate FROM Customer WHERE (RegisterDate BETWEEN '2007-01-06' AND DATEADD(s,-1,'2007-01-07'))
理解了以上兩條後,也就明白了為什麼BETWEEN '2007-01-06' AND '2007-01-06'是查不出’丁丁‘的。
因為 2007-01-06 等於 2007-01-06 0:00:00