日期:2014-05-17  浏览次数:20419 次

字符串 转日期
select * from catering  
where time between  convert(datetime,'2012-12-1 00:00:00',120) and convert(datetime,'2012-12-31 23:59:00',120) 


结果是查询到了  但是查询的数据不全

消息提示:
消息 241,级别 16,状态 1,第 1 行
从字符串转换日期和/或时间时,转换失败。



------解决方案--------------------
select * from catering  
where convert(datetime,time) between  '2012-12-1 00:00:00' and '2012-12-31 23:59:00'
------解决方案--------------------
引用:
已经解决了,数据库存放格式有点错误.":" 中英文状态下

一般如果报这种错误就用select输出转换一下
select convert(datetime,time) from catering  
然后加where条件,一点点的缩小范围或者写一个正则来检查插入错的数据
------解决方案--------------------
本帖最后由 roy_88 于 2013-01-03 10:41:08 编辑
改为这样


select * from catering  
where [time] >=  '2012-12-01' and [time]<'2013-01-01'