标签:错误 sel sele cas between 时间 摘要 padding ble
摘要:MS SQL 日期 Between
使用记录:
MSSQL 数据表(Table)
Key | Name | Date |
20150423001 | Johnny | 2015-04-23 01:53:09.957 |
20150423002 | Mary | 2015-04-23 22:54:33.607 |
SELECT * FROM Table WHERE Date BETWEEN ‘20150423‘ AND ‘20150423‘
SELECT * FROM Table WHERE Date BETWEEN CAST(‘20150423‘ AS DATETIME) AND CAST(‘20150423‘ AS DATETIME)
若使用以上两种语法皆会查询无数据,其语法应该修改如下:
SELECT * FROM Table WHERE Date BETWEEN CAST(‘20150423 00:00:00‘ AS DATETIME) AND CAST(‘20150423 23:59:29‘ AS DATETIME)
主要是加上时间,不然下列语法也可以查询到数据:
SELECT * FROM Table WHERE?Date >= ‘20150423‘ AND Date <= ‘20150423‘
一般应该比较常使用上述的语法吧!
有错误或更的好的方法,欢迎回复,非常感谢!
标签:错误 sel sele cas between 时间 摘要 padding ble
原文地址:https://www.cnblogs.com/petewell/p/11526747.html