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