IdNameRegisterDate
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

05-04 11:45